removed unnecessary structure
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 29 Oct 2020 03:23:56 +0000 (22:23 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 29 Oct 2020 03:23:56 +0000 (22:23 -0500)
src/ui.cpp

index 761ac011cffd2842f9ff9a88f6a57fbff07600fc..348a0af7818796a7388975e57025fa8de80a8ff8 100644 (file)
@@ -11,7 +11,7 @@
 #define FONT_CHAR_COUNT 96
 
 // NOTE(Brendan): This limits the maximum string length of a message to be 256 chars.
-#define FONT_BUFFER_SIZE sizeof(FontQuadVertex) * 256
+#define FONT_BUFFER_SIZE sizeof(stbtt_aligned_quad) * 256
 
 internal stbtt_packedchar *font_char_data;
 internal GLuint font_tex;
@@ -21,14 +21,6 @@ internal GLuint font_buffer_data;
 internal GLuint font_proj_mat_loc;
 internal GLuint font_color_loc;
 
-struct FontQuadVertex
-{
-    V2f pos_top_left;
-    V2f pos_bottom_right;
-    V2f tex_top_left;
-    V2f tex_bottom_right;
-};
-
 void
 init_font(const char* font_loc)
 {
@@ -108,10 +100,10 @@ init_font(const char* font_loc)
         glEnableVertexAttribArray(i);
         glVertexAttribDivisor(i, 1);
     }
-    glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(FontQuadVertex), (void *) offsetof(FontQuadVertex, pos_top_left));
-    glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(FontQuadVertex), (void *) offsetof(FontQuadVertex, pos_bottom_right));
-    glVertexAttribPointer(3, 2, GL_FLOAT, false, sizeof(FontQuadVertex), (void *) offsetof(FontQuadVertex, tex_top_left));
-    glVertexAttribPointer(4, 2, GL_FLOAT, false, sizeof(FontQuadVertex), (void *) offsetof(FontQuadVertex, tex_bottom_right));
+    glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(stbtt_aligned_quad), (void *) offsetof(stbtt_aligned_quad, x0));
+    glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(stbtt_aligned_quad), (void *) offsetof(stbtt_aligned_quad, x1));
+    glVertexAttribPointer(3, 2, GL_FLOAT, false, sizeof(stbtt_aligned_quad), (void *) offsetof(stbtt_aligned_quad, s0));
+    glVertexAttribPointer(4, 2, GL_FLOAT, false, sizeof(stbtt_aligned_quad), (void *) offsetof(stbtt_aligned_quad, s1));
     
     glBindBuffer(GL_ARRAY_BUFFER, -1);
     
@@ -129,28 +121,22 @@ void
 font_print(f32 x, f32 y, char* msg, f32 r, f32 g, f32 b, f32 a)
 {
     i32 msg_len = strlen(msg);
-    FontQuadVertex* quads = (FontQuadVertex *) alloca(msg_len * 6 * sizeof(FontQuadVertex));
+    stbtt_aligned_quad* quads = (stbtt_aligned_quad *) alloca(msg_len * sizeof(stbtt_aligned_quad));
     i32 quad_num = 0;
     
     while (*msg)
     {
-        stbtt_aligned_quad quad;
         stbtt_GetPackedQuad(font_char_data,
                             FONT_INTERNAL_IMAGE_SIZE, FONT_INTERNAL_IMAGE_SIZE,
                             *msg - FONT_FIRST_CHAR,
-                            &x, &y, &quad, 0);
-        
-        quads[quad_num].pos_top_left     = V2f { quad.x0, quad.y0 };
-        quads[quad_num].pos_bottom_right = V2f { quad.x1, quad.y1 };
-        quads[quad_num].tex_top_left     = V2f { quad.s0, quad.t0 };
-        quads[quad_num].tex_bottom_right = V2f { quad.s1, quad.t1 };
+                            &x, &y, &quads[quad_num], 0);
         
         msg++;
         quad_num++;
     }
     
     glBindBuffer(GL_ARRAY_BUFFER, font_buffer_data);
-    glBufferSubData(GL_ARRAY_BUFFER, 0, msg_len * sizeof(FontQuadVertex), quads);
+    glBufferSubData(GL_ARRAY_BUFFER, 0, msg_len * sizeof(stbtt_aligned_quad), quads);
     glBindBuffer(GL_ARRAY_BUFFER, -1);
     
     glBindTexture(GL_TEXTURE_2D, font_tex);