From: Brendan Hansen Date: Thu, 30 Dec 2021 03:56:31 +0000 (-0600) Subject: better vector printing X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d41837f06d66eabfa5daeedbc635af94fcd78b1e;p=voxel-shooter.git better vector printing --- diff --git a/src/font.onyx b/src/font.onyx index 9ba493d..ca0ca28 100644 --- a/src/font.onyx +++ b/src/font.onyx @@ -66,7 +66,7 @@ Font :: struct { } font_make :: (fd: FontDescriptor) -> Font { - texture_size :: 512; + texture_size :: 256; char_data := memory.make_slice(stbtt_packedchar, 96); @@ -107,7 +107,7 @@ font_make :: (fd: FontDescriptor) -> Font { font_print :: (font: Font, x, y: f32, format: str, va: ..any) { buf: [1024] u8; - msg := conv.str_format_va(buf, format, va); + msg := conv.format_va(buf, format, va); font_draw(font, x, y, msg); } diff --git a/src/main.onyx b/src/main.onyx index 5467f5e..44881a0 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -96,7 +96,7 @@ setup_opengl :: () { world = world_make(); __initialize(^camera); - camera.position = .{5,5,5}; + camera.position = .{0,0,0}; camera_set_fov(^camera, 75); ww, wh: i32; glfwGetWindowSize(window, ^ww, ^wh); @@ -191,8 +191,8 @@ update :: (dt: f32) { } draw :: () { - // glClearColor(.7, .7, .9, 1); - glClearColor(0.1, 0.1, 0.1, 1); + glClearColor(.7, .7, .9, 1); + // glClearColor(0.1, 0.1, 0.1, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shader_use(world_shader); diff --git a/src/vecmath.onyx b/src/vecmath.onyx index bf6b7d7..35c9130 100644 --- a/src/vecmath.onyx +++ b/src/vecmath.onyx @@ -1,12 +1,12 @@ -Vector2 :: struct { +Vector2 :: struct [conv.Custom_Format.{format_vector2}] { x, y: f32; } -Vector3i :: struct { +Vector3i :: struct [conv.Custom_Format.{format_vector3i}] { x, y, z: i32; } -Vector3 :: struct { +Vector3 :: struct [conv.Custom_Format.{format_vector3}] { x, y, z: f32; mag :: macro (v: Vector3) => math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); @@ -34,3 +34,35 @@ Vector3 :: struct { #operator + macro (v1, v2: Vector3) => Vector3.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z }; #operator - macro (v1, v2: Vector3) => Vector3.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z }; #operator * macro (v: Vector3, s: f32) => Vector3.{ v.x * s, v.y * s, v.z * s }; + +#local { + conv :: package core.conv + + format_vector2 :: (output: ^conv.Format_Output, format: ^conv.Format, v: ^Vector2) { + output->write("("); + conv.format_any(output, format, .{^v.x, f32}); + output->write(", "); + conv.format_any(output, format, .{^v.y, f32}); + output->write(")"); + } + + format_vector3 :: (output: ^conv.Format_Output, format: ^conv.Format, v: ^Vector3) { + output->write("("); + conv.format_any(output, format, .{^v.x, f32}); + output->write(", "); + conv.format_any(output, format, .{^v.y, f32}); + output->write(", "); + conv.format_any(output, format, .{^v.z, f32}); + output->write(")"); + } + + format_vector3i :: (output: ^conv.Format_Output, format: ^conv.Format, v: ^Vector3i) { + output->write("("); + conv.format_any(output, format, .{^v.x, i32}); + output->write(", "); + conv.format_any(output, format, .{^v.y, i32}); + output->write(", "); + conv.format_any(output, format, .{^v.z, i32}); + output->write(")"); + } +} \ No newline at end of file