summaryrefslogtreecommitdiff
path: root/src/render/gl_2d_font.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/gl_2d_font.cpp')
-rw-r--r--src/render/gl_2d_font.cpp43
1 files changed, 31 insertions, 12 deletions
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 );
}