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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import "core:fmt"
import gpu "../.."
import app "../../app"
import particles "../../particles"
main :: proc() {
state, ok := app.init_window(800, 600, "GPU - Particles")
if !ok {
return
}
defer app.shutdown(&state)
config := particles.default_config()
config.max_particles = 500
config.emission_rate = 100
config.start_color = gpu.ORANGE
config.end_color = {1, 0, 0, 0}
config.gravity = {0, 200}
config.speed = {80, 180}
config.spread = 45
ps, ps_ok := particles.init(config)
defer particles.destroy(&ps)
if !ps_ok {
fmt.println("Failed to create particle system")
return
}
// Second system for click bursts
burst_config := particles.default_config()
burst_config.max_particles = 200
burst_config.emission_rate = 0 // burst-only
burst_config.start_color = gpu.CYAN
burst_config.end_color = {0, 0.5, 1, 0}
burst_config.speed = {100, 250}
burst_config.spread = 180 // omnidirectional
burst_config.gravity = {0, 100}
burst_config.start_size = 5
burst_config.end_size = 1
burst, burst_ok := particles.init(burst_config)
defer particles.destroy(&burst)
if !burst_ok {
fmt.println("Failed to create burst particle system")
return
}
for !app.window_should_close(&state) {
mouse := app.get_mouse_position(&state)
// Continuous emission follows mouse
particles.update(&ps, mouse, app.get_frame_time(&state))
// Burst on click
particles.update(&burst, mouse, app.get_frame_time(&state))
if app.is_mouse_button_pressed(&state, .Left) {
particles.emit(&burst, mouse, 50)
}
frame := app.begin_frame(&state, {0.05, 0.05, 0.08, 1.0})
_ = gpu.push_layer(&frame, {name = "particles", sort_base = 0, order = .Sortable})
particles.draw_2d(&frame, &ps, .Sortable, 0)
particles.draw_2d(&frame, &burst, .Sortable, 10_000)
_ = gpu.pop_layer(&frame)
_ = gpu.push_layer(&frame, {name = "overlay", sort_base = 100_000, order = .Strict})
_ = gpu.draw_rect(&frame, {x = 5, y = 5, width = 80, height = 20, color = {0, 0, 0, 0.5}, order = .Strict})
gpu.draw_text_frame(&frame, {
text = fmt.tprintf("FPS: %d", app.get_fps(&state)),
x = 10,
y = 9,
color = gpu.WHITE,
scale = 2,
order = .Strict,
sort_key = 1,
})
_ = gpu.pop_layer(&frame)
_ = app.submit_frame(&state, &frame)
if app.is_key_pressed(&state, .Escape) {
break
}
}
}