Add outline pass to cubes

This commit is contained in:
Hugo Mårdbrink 2025-08-27 00:16:42 +02:00
parent 1852cf3a7f
commit 2ee22c118c
10 changed files with 425 additions and 108 deletions

View file

@ -21,10 +21,11 @@ import sa "sokol/app"
import sh "sokol/helpers"
import "ecs"
import program_config "config"
Vec2 :: [2]f32
Vec3 :: [3]f32
Vec4 :: [4]f32
Vec2 :: ecs.Vec2
Vec3 :: ecs.Vec3
Vec4 :: ecs.Vec4
Globals :: struct {
coordinator: ecs.Coordinator,
@ -34,6 +35,7 @@ Globals :: struct {
render_system: ^ecs.RenderSystem,
time_since_cube: f32,
current_color: i32,
}
g: ^Globals
@ -50,7 +52,7 @@ main :: proc() {
default_context = context
sa.run({
window_title = "ECS Test",
window_title = program_config.WINDOW_TITLE,
allocator = sa.Allocator(sh.allocator(&default_context)),
logger = sa.Logger(sh.logger(&default_context)),
@ -80,14 +82,14 @@ frame_cb:: proc "c" () {
dt := f32(sa.frame_duration())
g.time_since_cube += dt
if g.time_since_cube >= 0.2 {
create_cube()
if g.time_since_cube >= program_config.SPAWN_INTERVAL {
g.time_since_cube = 0
create_cube()
}
ecs.physics_system_update(g.physics_system, &g.coordinator, dt)
ecs.camera_system_update(g.camera_system, &g.coordinator, dt)
ecs.render_system_update(g.render_system, &g.coordinator, dt)
ecs.render_system_update(g.render_system, &g.coordinator)
ecs.input_system_mouse_reset(g.input_system, &g.coordinator)
}
@ -115,7 +117,7 @@ create_cube :: proc() {
&g.coordinator,
entity,
ecs.GravityComponent{
ecs.Vec3{ 0.0, -2.5, 0.0 }
ecs.Vec3{ 0.0, program_config.GRAVITY_CONSTANT, 0.0 }
})
ecs.coordinator_add_component(
ecs.RigidBodyComponent,
@ -131,25 +133,23 @@ create_cube :: proc() {
entity,
ecs.TransformComponent{
position = Vec3{
f32(rand.int_max(50)),
f32(rand.int_max(program_config.SPAWN_AREA)),
10,
f32(rand.int_max(50)),
f32(rand.int_max(program_config.SPAWN_AREA)),
},
rotation = ecs.Vec3{0.0, 0.0, 0.0},
scale = ecs.Vec3{1.0, 1.0, 1.0},
rotation = ecs.Vec3{ 0.0, 0.0, 0.0 },
scale = ecs.Vec3{ 1.0, 1.0, 1.0 },
})
ecs.coordinator_add_component(
ecs.ColorComponent,
&g.coordinator,
entity,
ecs.ColorComponent{
color = Vec4{
rand.float32_uniform(0,1),
rand.float32_uniform(0,1),
rand.float32_uniform(0,1),
rand.float32_uniform(0,1),
},
color = program_config.CUBE_COLORS[g.current_color]
})
g.current_color += 1
g.current_color %= i32(len(program_config.CUBE_COLORS))
ecs.coordinator_add_component(
ecs.MeshComponent,
&g.coordinator,
@ -162,7 +162,7 @@ create_cube :: proc() {
&g.coordinator,
entity,
ecs.MaterialComponent{
material_id = .Grid
material_id = .Cube
})
}
@ -208,12 +208,12 @@ create_scene :: proc() {
&g.coordinator,
user_entity,
ecs.CameraComponent{
position = { 30, 0, 60 },
position = program_config.START_POSITION,
target = { 0, 0, 1 },
look = { 0, 0 },
movement_speed = 3.0,
look_sensitivity = 0.15,
movement_speed = program_config.MOVEMENT_SPEED,
look_sensitivity = program_config.LOOK_SENSITIVITY,
})
ecs.coordinator_add_component(