Uniform colors

This commit is contained in:
2026-02-03 20:31:12 +01:00
parent b80c321e84
commit 4394179a71
6 changed files with 189 additions and 48 deletions

47
color.odin Normal file
View File

@@ -0,0 +1,47 @@
package renderer
import "core:math/rand"
Color :: union {
RGB_Color,
RGBA_Color,
}
RGB_Color :: [3]u8
RGBA_Color :: [4]u8
color_to_f32 :: proc {
rgb_color_to_f32_array,
rgba_color_to_f32_array,
}
rgb_color_to_f32_array :: proc(color: RGB_Color) -> [3]f32 {
return {
f32(color.r) / f32(max(u8)),
f32(color.g) / f32(max(u8)),
f32(color.b) / f32(max(u8)),
}
}
rgba_color_to_f32_array :: proc(color: RGBA_Color) -> [4]f32 {
return {
f32(color.r) / f32(max(u8)),
f32(color.g) / f32(max(u8)),
f32(color.b) / f32(max(u8)),
f32(color.a) / f32(max(u8)),
}
}
get_random_color_rgb :: proc() -> RGB_Color {
r := u8(rand.uint32() / u32(max(u8)))
g := u8(rand.uint32() / u32(max(u8)))
b := u8(rand.uint32() / u32(max(u8)))
return { r, g, b }
}
get_random_color_rgba :: proc() -> RGBA_Color {
c := get_random_color_rgb()
a := u8(rand.uint32() / u32(max(u8)))
return { c.r, c.g, c.b, a }
}