From ba6d14a7737ef7cd02b61586e39ca2162df3018d Mon Sep 17 00:00:00 2001 From: Kasullian Date: Mon, 8 Sep 2025 23:20:06 -0400 Subject: glew, map parsing for windows --- src/render/gl_2d_font.cpp | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'src/render/gl_2d_font.cpp') diff --git a/src/render/gl_2d_font.cpp b/src/render/gl_2d_font.cpp index 1dc498b..a104124 100644 --- a/src/render/gl_2d_font.cpp +++ b/src/render/gl_2d_font.cpp @@ -207,24 +207,38 @@ void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 origin, const gl_font_calc_vertices_uvs( font, origin, text, _scale, vertices, indices, coords, clr ); glUseProgram( shader->id ); + glBindVertexArray( shader->gl->vao ); glBindBuffer( GL_ARRAY_BUFFER, shader->gl->vbuffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(VERTEX) * 6 * len, vertices, GL_STATIC_DRAW ); + I32 position = glGetAttribLocation( shader->id, "in_pos" ); - glEnableVertexAttribArray( position ); - glVertexAttribPointer( position, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->pos ); - I32 color = glGetAttribLocation( shader->id, "in_clr" ); - glEnableVertexAttribArray( color ); - glVertexAttribPointer( color, 4, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->clr ); - I32 texcoord = glGetAttribLocation( shader->id, "in_texcoord" ); - glEnableVertexAttribArray( texcoord ); - glVertexAttribPointer( texcoord, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->uv ); - I32 sampler = glGetAttribLocation( shader->id, "in_sampler" ); - glEnableVertexAttribArray( sampler ); - glVertexAttribPointer( sampler, 1, GL_UNSIGNED_BYTE, 1, sizeof(VERTEX), &( (VERTEX*)nullptr)->sampler ); + + if (position >= 0) { + glEnableVertexAttribArray( position ); + glVertexAttribPointer( position, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->pos ); + } + + if (color >= 0) { + glEnableVertexAttribArray( color ); + glVertexAttribPointer( color, 4, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->clr ); + } + + if (texcoord >= 0) { + glEnableVertexAttribArray( texcoord ); + glVertexAttribPointer( texcoord, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->uv ); + } + + if (sampler >= 0) { + glEnableVertexAttribArray( sampler ); + glVertexAttribPointer( sampler, 1, GL_UNSIGNED_BYTE, 1, sizeof(VERTEX), &( (VERTEX*)nullptr)->sampler ); + } + + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, font->atlas->id ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); @@ -234,10 +248,12 @@ void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 origin, const glDrawElements( GL_TRIANGLES, len * 6, GL_UNSIGNED_SHORT, indices ); glBindTexture( GL_TEXTURE_2D, 0 ); - + free( vertices ); free( indices ); free( coords ); + + glBindVertexArray( 0 ); } void gl_font_textured( @@ -272,6 +288,7 @@ void gl_font_textured( } glUseProgram( shader->id ); + glBindVertexArray( shader->gl->vao ); glBindBuffer( GL_ARRAY_BUFFER, shader->gl->vbuffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(FONT_CUSTOM_VERTEX) * 6 * len, custom_vertices, GL_STATIC_DRAW ); @@ -303,6 +320,8 @@ void gl_font_textured( free( indices ); free( coords ); free( custom_vertices ); + + glBindVertexArray( 0 ); } -- cgit v1.2.3 From 235926dadb686589f0b5480162c3ab929159e570 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 10 Sep 2025 12:25:00 +0200 Subject: unfuck --- src/render/gl_2d_font.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/render/gl_2d_font.cpp') diff --git a/src/render/gl_2d_font.cpp b/src/render/gl_2d_font.cpp index a104124..329f0be 100644 --- a/src/render/gl_2d_font.cpp +++ b/src/render/gl_2d_font.cpp @@ -211,31 +211,23 @@ void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 origin, const glBindBuffer( GL_ARRAY_BUFFER, shader->gl->vbuffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(VERTEX) * 6 * len, vertices, GL_STATIC_DRAW ); - + I32 position = glGetAttribLocation( shader->id, "in_pos" ); I32 color = glGetAttribLocation( shader->id, "in_clr" ); I32 texcoord = glGetAttribLocation( shader->id, "in_texcoord" ); I32 sampler = glGetAttribLocation( shader->id, "in_sampler" ); - - if (position >= 0) { - glEnableVertexAttribArray( position ); - glVertexAttribPointer( position, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->pos ); - } - if (color >= 0) { - glEnableVertexAttribArray( color ); - glVertexAttribPointer( color, 4, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->clr ); - } + glEnableVertexAttribArray( position ); + glVertexAttribPointer( position, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->pos ); - if (texcoord >= 0) { - glEnableVertexAttribArray( texcoord ); - glVertexAttribPointer( texcoord, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->uv ); - } + glEnableVertexAttribArray( color ); + glVertexAttribPointer( color, 4, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->clr ); - if (sampler >= 0) { - glEnableVertexAttribArray( sampler ); - glVertexAttribPointer( sampler, 1, GL_UNSIGNED_BYTE, 1, sizeof(VERTEX), &( (VERTEX*)nullptr)->sampler ); - } + glEnableVertexAttribArray( texcoord ); + glVertexAttribPointer( texcoord, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->uv ); + + glEnableVertexAttribArray( sampler ); + glVertexAttribPointer( sampler, 1, GL_UNSIGNED_BYTE, 1, sizeof(VERTEX), &( (VERTEX*)nullptr)->sampler ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, font->atlas->id ); -- cgit v1.2.3 From e2366afb57d69f3952bbb4d1894d82293cd1cb9d Mon Sep 17 00:00:00 2001 From: Kasullian Date: Wed, 10 Sep 2025 07:16:42 -0400 Subject: remove unnecessary code --- src/render/gl_2d_font.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/render/gl_2d_font.cpp') diff --git a/src/render/gl_2d_font.cpp b/src/render/gl_2d_font.cpp index 329f0be..10ae71a 100644 --- a/src/render/gl_2d_font.cpp +++ b/src/render/gl_2d_font.cpp @@ -207,7 +207,6 @@ void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 origin, const gl_font_calc_vertices_uvs( font, origin, text, _scale, vertices, indices, coords, clr ); glUseProgram( shader->id ); - glBindVertexArray( shader->gl->vao ); glBindBuffer( GL_ARRAY_BUFFER, shader->gl->vbuffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(VERTEX) * 6 * len, vertices, GL_STATIC_DRAW ); @@ -244,8 +243,6 @@ void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 origin, const free( vertices ); free( indices ); free( coords ); - - glBindVertexArray( 0 ); } void gl_font_textured( @@ -280,7 +277,6 @@ void gl_font_textured( } glUseProgram( shader->id ); - glBindVertexArray( shader->gl->vao ); glBindBuffer( GL_ARRAY_BUFFER, shader->gl->vbuffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(FONT_CUSTOM_VERTEX) * 6 * len, custom_vertices, GL_STATIC_DRAW ); @@ -312,8 +308,6 @@ void gl_font_textured( free( indices ); free( coords ); free( custom_vertices ); - - glBindVertexArray( 0 ); } -- cgit v1.2.3