1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import "core:fmt"
import gpu "../.."
import app "../../app"
// Generate a 64x64 checkerboard texture (magenta/white)
gen_checkerboard :: proc() -> gpu.Texture {
W :: 64
pixels: [W * W * 4]u8
for y in 0..<W {
for x in 0..<W {
i := (y * W + x) * 4
dark := ((x / 8) + (y / 8)) % 2 == 0
if dark {
pixels[i + 0] = 255 // R
pixels[i + 1] = 0 // G
pixels[i + 2] = 255 // B
pixels[i + 3] = 255 // A
} else {
pixels[i + 0] = 255
pixels[i + 1] = 255
pixels[i + 2] = 255
pixels[i + 3] = 255
}
}
}
return gpu.load_texture_from_rgba(pixels[:], W, W)
}
main :: proc() {
state, ok := app.init_window(800, 600, "GPU - Textured Quad")
if !ok {
return
}
defer app.shutdown(&state)
// Try loading from file, fall back to generated checkerboard
tex := gpu.load_texture("tests/assets/test.png")
if tex.id == 0 {
fmt.println("PNG load failed, using generated checkerboard")
tex = gen_checkerboard()
} else {
fmt.printfln("Loaded tests/assets/test.png: %dx%d, id=%d", tex.width, tex.height, tex.id)
}
defer gpu.unload_texture(tex)
fmt.printfln("Texture: id=%d, %dx%d", tex.id, tex.width, tex.height)
for !app.window_should_close(&state) {
frame := app.begin_frame(&state, gpu.CORNFLOWER_BLUE)
// Draw textured quad
if tex.id != 0 {
_ = gpu.draw_texture_quad(&frame, {
texture = tex,
x = 100,
y = 100,
color = gpu.WHITE,
})
}
// Draw colored rectangle alongside (proves unified pipeline)
_ = gpu.draw_rect(&frame, {x = 500, y = 200, width = 150, height = 100, color = gpu.RED})
_ = gpu.draw_circle_frame(&frame, {cx = 600, cy = 400, radius = 50, color = gpu.GREEN})
_ = app.submit_frame(&state, &frame)
if app.is_key_pressed(&state, .Escape) {
break
}
}
}