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.cpp67
1 files changed, 5 insertions, 62 deletions
diff --git a/src/render/gl_2d_font.cpp b/src/render/gl_2d_font.cpp
index 10ae71a..6533dce 100644
--- a/src/render/gl_2d_font.cpp
+++ b/src/render/gl_2d_font.cpp
@@ -145,7 +145,6 @@ void gl_font_calc_vertices_uvs(
F32 _scale,
VERTEX* vertices,
U16* indices,
- VEC2* coords,
CLR clr
) {
U32 len = (U32)strlen( text );
@@ -199,13 +198,12 @@ void gl_font_calc_vertices_uvs(
}
}
-void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 origin, const char* text, CLR clr, F32 _scale ) {
+void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 pos, const char* text, CLR clr, F32 _scale ) {
U32 len = strlen( text );
VERTEX* vertices = (VERTEX*)malloc( sizeof(VERTEX) * 6 * len );
U16* indices = (U16*)malloc( sizeof(U16) * 6 * len );
- VEC2* coords = (VEC2*)malloc( sizeof(VEC2) * 6 * len );
- gl_font_calc_vertices_uvs( font, origin, text, _scale, vertices, indices, coords, clr );
+ gl_font_calc_vertices_uvs( font, pos, text, _scale, vertices, indices, clr );
glUseProgram( shader->id );
glBindBuffer( GL_ARRAY_BUFFER, shader->gl->vbuffer );
@@ -242,75 +240,20 @@ void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 origin, const
free( vertices );
free( indices );
- free( coords );
}
-void gl_font_textured(
- GL_FONT* font,
- GL_SHADER_PROGRAM* shader,
- VEC2 origin,
- const char* text,
- GL_TEX2D* tex,
- CLR clr,
- F32 _scale
-) {
+void gl_font_draw( GL_FONT* font, GL_BATCH2D* batch, VEC2 pos, const char* text, CLR clr, F32 _scale ) {
U32 len = strlen( text );
- struct FONT_CUSTOM_VERTEX {
- VERTEX v;
- VEC2 uv2;
- };
-
- FONT_CUSTOM_VERTEX* custom_vertices = (FONT_CUSTOM_VERTEX*)malloc( sizeof(FONT_CUSTOM_VERTEX) * 6 * len );
VERTEX* vertices = (VERTEX*)malloc( sizeof(VERTEX) * 6 * len );
U16* indices = (U16*)malloc( sizeof(U16) * 6 * len );
- VEC2* coords = (VEC2*)malloc( sizeof(VEC2) * 6 * len );
-
- gl_font_calc_vertices_uvs( font, origin, text, _scale, vertices, indices, coords, clr );
- VEC2 dim = gl_font_dim( font, text, _scale );
-
- for( U32 i = 0; i < len * 6; ++i ) {
- custom_vertices[i].v = vertices[i];
- custom_vertices[i].uv2 = {
- (vertices[i].pos.x - origin.x) / dim.x,
- (vertices[i].pos.y - origin.y - vertices[0].pos.y) / dim.y
- };
- }
- glUseProgram( shader->id );
-
- glBindBuffer( GL_ARRAY_BUFFER, shader->gl->vbuffer );
- glBufferData( GL_ARRAY_BUFFER, sizeof(FONT_CUSTOM_VERTEX) * 6 * len, custom_vertices, GL_STATIC_DRAW );
- I32 position = glGetAttribLocation( shader->id, "in_pos" );
- glEnableVertexAttribArray( position );
- glVertexAttribPointer( position, 2, GL_FLOAT, 0, sizeof(FONT_CUSTOM_VERTEX), 0 );
-
- I32 texcoord = glGetAttribLocation( shader->id, "in_texcoord" );
- glEnableVertexAttribArray( texcoord );
- glVertexAttribPointer( texcoord, 2, GL_FLOAT, 0, sizeof(FONT_CUSTOM_VERTEX), (void*)(sizeof(VEC2)) );
-
- I32 texcoord2 = glGetAttribLocation( shader->id, "in_texcoord2" );
- glEnableVertexAttribArray( texcoord2 );
- glVertexAttribPointer( texcoord2, 2, GL_FLOAT, 0, sizeof(FONT_CUSTOM_VERTEX), (void*)(sizeof(VERTEX)) );
-
- glBindBuffer( GL_ARRAY_BUFFER, 0 );
-
- I32 color = glGetUniformLocation( shader->id, "in_color" );
- glUniform4fv( color, 1, (F32*)&clr );
-
- glActiveTexture( GL_TEXTURE0 );
- glUniform1iv( glGetUniformLocation( shader->id, "in_sampler" ), 0, 0 );
- glBindTexture( GL_TEXTURE_2D, font->atlas->id );
-
- glDrawElements( GL_TRIANGLES, len * 6, GL_UNSIGNED_SHORT, indices );
- glBindTexture( GL_TEXTURE_2D, 0 );
+ gl_font_calc_vertices_uvs( font, pos, text, _scale, vertices, indices, clr );
+ gl_batch_insert( batch, vertices, len * 6, font->atlas, GL_TRIANGLES );
free( vertices );
free( indices );
- free( coords );
- free( custom_vertices );
}
-
VEC2 gl_font_dim( GL_FONT* font, const char* text, F32 _scale ) {
U32 len = strlen( text );