+static void ui_reset_colours( ui_ctx *ctx );
+static void ui_init_context( ui_ctx *ctx, int index_buffer_size )
+{
+ ui_reset_colours( ctx );
+
+ u32 vertex_buffer_size = (index_buffer_size+(index_buffer_size/2));
+
+ // Generate the buffer we are gonna be drawing to
+ {
+ glGenVertexArrays(1, &ctx->vao);
+ glGenBuffers( 1, &ctx->vbo );
+ glGenBuffers( 1, &ctx->ebo );
+ glBindVertexArray( ctx->vao );
+
+ glBindBuffer( GL_ARRAY_BUFFER, ctx->vbo );
+
+ glBufferData( GL_ARRAY_BUFFER, vertex_buffer_size * sizeof( struct ui_vert ), NULL, GL_DYNAMIC_DRAW );
+ glBindVertexArray( ctx->vao );
+
+ glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ctx->ebo );
+ glBufferData( GL_ELEMENT_ARRAY_BUFFER, index_buffer_size * sizeof( u16 ), NULL, GL_DYNAMIC_DRAW );
+
+ u32 const stride = sizeof( struct ui_vert );
+
+ // XY
+ glVertexAttribPointer( 0, 2, GL_SHORT, GL_FALSE, stride, (void *)offsetof( struct ui_vert, co ) );
+ glEnableVertexAttribArray( 0 );
+
+ // UV
+ glVertexAttribPointer( 1, 2, GL_UNSIGNED_BYTE, GL_FALSE, stride, (void *)offsetof( struct ui_vert, uv ) );
+ glEnableVertexAttribArray( 1 );
+
+ // COLOUR
+ glVertexAttribPointer( 2, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, (void *)offsetof( struct ui_vert, colour ) );
+ glEnableVertexAttribArray( 2 );
+
+ // CLIPPING
+ glVertexAttribPointer( 3, 4, GL_SHORT, GL_FALSE, stride, (void *)offsetof( struct ui_vert, clip ) );
+ glEnableVertexAttribArray( 3 );
+ }
+
+ // Initialize default context
+ {
+ ctx->verts = (struct ui_vert *)malloc( vertex_buffer_size * sizeof(struct ui_vert) );
+ ctx->indices = (u16*)malloc( index_buffer_size * sizeof(u16) );
+ }
+}
+
+static void ui_context_free( ui_ctx *ctx )
+{
+ glDeleteVertexArrays( 1, &ctx->vao );
+ glDeleteBuffers( 1, &ctx->vbo );
+ glDeleteBuffers( 1, &ctx->ebo );
+
+ free( ctx->verts );
+ free( ctx->indices );
+}
+