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
package main
import "core:fmt"
import gpu "../.."
import app "../../app"
import particles "../../particles"
main :: proc() {
state, ok := app.init_window(800, 600, "GPU - 3D Particles")
if !ok {
return
}
defer app.shutdown(&state)
camera := gpu.default_camera_3d()
camera.position = {3, 2, 5}
camera.target = {0, 1, 0}
config := particles.default_config_3d()
config.max_particles = 300
config.emission_rate = 60
config.direction = {0, 1, 0}
config.gravity = {0, -4, 0}
config.speed = {1, 3}
config.spread = 25
config.start_color = {1, 0.6, 0.1, 1}
config.end_color = {1, 0, 0, 0}
config.start_size = 0.12
config.end_size = 0.02
config.lifetime = {0.8, 2.0}
ps, ps_ok := particles.init_3d(config)
defer particles.destroy_3d(&ps)
if !ps_ok {
fmt.println("Failed to create 3D particle producer")
return
}
for !app.window_should_close(&state) {
app.update_camera(&state, &camera, .ORBITAL)
particles.update_3d(&ps, {0, 0, 0}, app.get_frame_time(&state))
frame := app.begin_frame(&state, {0.08, 0.08, 0.12, 1.0})
gpu.set_camera_3d(&frame, camera)
_ = gpu.draw_grid_frame(&frame, {slices = 10, spacing = 1})
particles.draw_3d(&frame, &ps)
fps_text := fmt.tprintf("FPS: %d", app.get_fps(&state))
_ = gpu.draw_rect(&frame, {x = 5, y = 5, width = 80, height = 20, color = {0, 0, 0, 0.5}, sort_key = 10_000})
gpu.draw_text_frame(&frame, {text = fps_text, x = 10, y = 9, color = gpu.WHITE, scale = 2, sort_key = 10_001})
_ = app.submit_frame(&state, &frame)
if app.is_key_pressed(&state, .Escape) {
break
}
}
}