+ /* 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 );
+
+ VG_CHECK_GL_ERR();
+
+ /* Set pointers */
+ 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 );
+
+ VG_CHECK_GL_ERR();
+
+ /* Alloc RAM default context */
+ ctx->verts = (struct ui_vert *)vg_alloc(
+ vertex_buffer_size * sizeof(struct ui_vert) );
+ if( !ctx->verts )
+ goto il_fail_alloc_verts;
+
+ ctx->indices = (u16*)vg_alloc( index_buffer_size * sizeof(u16) );
+ if( !ctx->indices )
+ goto il_fail_alloc_indices;
+
+ if( !ctx->colours )
+ ctx->colours = &ui_default_colours;
+
+ return 1;
+
+ vg_free( ctx->indices );
+ ctx->indices = NULL;
+il_fail_alloc_indices:
+ vg_free( ctx->verts );
+ ctx->verts = NULL;
+il_fail_alloc_verts:
+ glDeleteBuffers( 1, &ctx->ebo );
+ glDeleteBuffers( 1, &ctx->vbo );
+ glDeleteVertexArrays( 1, &ctx->vao );
+ VG_CHECK_GL_ERR();
+ return 0;