+
+ // Create text buffers
+ {
+ // Work out the counts for each 'segment'
+ u32 desc_max_size = 0, title_max_size = 0,
+ score_max_size = 10,
+ time_max_size = 10,
+
+ size_level_texts = 6*9*7
+ ;
+
+ for( int i = 0; i < vg_list_size( career_packs ); i ++ )
+ {
+ struct career_level_pack *set = &career_packs[i];
+ for( int j = 0; j < set->count; j ++ )
+ {
+ struct cmp_level *lvl = &set->pack[j];
+
+ desc_max_size = VG_MAX( desc_max_size, strlen( lvl->description ) );
+ title_max_size = VG_MAX( title_max_size, strlen( lvl->title ) );
+ }
+ }
+
+ // Full buffer
+ u32 total_characters =
+ title_max_size +
+ desc_max_size +
+ score_max_size +
+ time_max_size +
+ size_level_texts;
+
+ u32 total_faces = total_characters * 2,
+ total_vertices = total_characters * 4,
+ total_indices = total_faces * 3;
+
+ // Working buffer
+ u32 work_buffer_total_chars =
+ VG_MAX( 7, VG_MAX( VG_MAX( desc_max_size, title_max_size ), VG_MAX( score_max_size, time_max_size ) ) );
+
+ u32 total_work_faces = work_buffer_total_chars * 2,
+ total_work_vertices = work_buffer_total_chars * 4,
+ total_work_indices = total_work_faces * 3;
+
+ text_buffers.title_count = 0;
+ text_buffers.desc_count = 0;
+ text_buffers.score_count = 0;
+ text_buffers.time_count = 0;
+ text_buffers.grid_count = size_level_texts;
+
+ // Calculate offsets
+ text_buffers.title_start = 0;
+ text_buffers.desc_start = text_buffers.title_start + title_max_size;
+ text_buffers.score_start = text_buffers.desc_start + desc_max_size;
+ text_buffers.time_start = text_buffers.score_start + score_max_size;
+ text_buffers.grid_start = text_buffers.time_start + time_max_size;
+
+ // Opengl
+ glGenVertexArrays(1, &text_buffers.vao);
+ glGenBuffers( 1, &text_buffers.vbo );
+ glGenBuffers( 1, &text_buffers.ebo );
+ glBindVertexArray( text_buffers.vao );
+
+ glBindBuffer( GL_ARRAY_BUFFER, text_buffers.vbo );
+ glBufferData( GL_ARRAY_BUFFER, total_vertices * sizeof( struct vector_glyph_vert ), NULL, GL_DYNAMIC_DRAW );
+
+ glBindVertexArray( text_buffers.vao );
+
+ glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, text_buffers.ebo );
+ glBufferData( GL_ELEMENT_ARRAY_BUFFER, total_indices * sizeof( u16 ), NULL, GL_DYNAMIC_DRAW );
+
+ u32 const stride = sizeof( struct vector_glyph_vert );
+
+ // XY
+ glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, stride, (void *)offsetof( struct vector_glyph_vert, co ) );
+ glEnableVertexAttribArray( 0 );
+
+ // UV
+ glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, stride, (void *)offsetof( struct vector_glyph_vert, uv ) );
+ glEnableVertexAttribArray( 1 );
+
+ // COLOUR
+ glVertexAttribPointer( 2, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, (void *)offsetof( struct vector_glyph_vert, colour ) );
+ glEnableVertexAttribArray( 2 );
+
+ // Offline memory
+ text_buffers.buffer = (struct vector_glyph_vert *)malloc( total_work_vertices * sizeof(struct vector_glyph_vert) );
+ text_buffers.indices = (u16*)malloc( total_work_indices * sizeof(u16) );
+
+ char label[8];
+ for( int i = 1; i < 7; i ++ )
+ label[i] = ' ';
+ label[7] = 0x00;
+
+ // Reset grid
+ for( int x = 0; x < 6; x ++ )
+ {
+ for( int y = 0; y < 9; y ++ )
+ {
+ label[0] = ' ';
+
+ if( x == 0 )
+ {
+ if( y != 8 )
+ label[0] = 'A' + y;
+ }
+ else if( y == 8 )
+ {
+ label[0] = '0' + x;
+ }
+
+ gen_text_buffer( label, &font_Ubuntu, (v2f){ -6.0f + x + (x == 0? 0.6f: 0.2f), y + 0.2f }, 0.35f, text_buffers.grid_start+(y*6+x)*7 );
+ }
+ }
+ }