better vector printing
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 30 Dec 2021 03:56:31 +0000 (21:56 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 30 Dec 2021 03:56:31 +0000 (21:56 -0600)
src/font.onyx
src/main.onyx
src/vecmath.onyx

index 9ba493d29cc25feeb149884126b65eeca649f77f..ca0ca281bcde7fcb8ed1171ea3888a778233d766 100644 (file)
@@ -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);
 }
 
index 5467f5edba915dfee5b655406af352f54f132c92..44881a00f2c96c6ae3e5d37d0f266e0e2038253e 100644 (file)
@@ -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);
index bf6b7d7c2aac58029999474b430091b66c73a53d..35c913063931f1610aef3e50db6c70707e5ed17e 100644 (file)
@@ -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