From bfc464b5681780975bb3fdc2361dd49e6a4dd986 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 28 Oct 2020 22:23:56 -0500 Subject: [PATCH] removed unnecessary structure --- src/ui.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/ui.cpp b/src/ui.cpp index 761ac01..348a0af 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -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); -- 2.25.1