X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_ui.h;h=dc0cceec4288b3dbeb7365d29846e273ad72a918;hb=3d52e114a0f608e58bc99cfc6faaeb41cfcf84c7;hp=8e73da5a1ab5a208432ba27e359a9b77f6653da2;hpb=a7938c00a8c486ad0e2a765c3092017487ba761e;p=vg.git diff --git a/vg_ui.h b/vg_ui.h index 8e73da5..dc0ccee 100644 --- a/vg_ui.h +++ b/vg_ui.h @@ -74,6 +74,66 @@ static struct vg_shader _shader_ui = } }; +static struct vg_shader _shader_ui_image = +{ + .name = "[vg] ui_image", + .link = NULL, + .vs = + { + .orig_file = NULL, + .static_src = + "layout (location=0) in vec2 a_co;" + "layout (location=1) in vec2 a_uv;" + "layout (location=2) in vec4 a_colour;" + "layout (location=3) in vec4 a_clip;" + "uniform mat3 uPv;" + "" + "out vec2 aTexCoords;" + "out vec4 aColour;" + "out vec2 aWsp;" + "out vec4 aClip;" + "" + "void main()" + "{" + "gl_Position = vec4( uPv * vec3( a_co, 1.0 ), 1.0 );" + "aTexCoords = a_uv * 0.0078125;" + "aColour = a_colour;" + + "aWsp = a_co;" + "aClip = a_clip;" + "}", + }, + .fs = + { + .orig_file = NULL, + .static_src = + "uniform sampler2D uTexImage;" + "out vec4 FragColor;" + "" + "in vec2 aTexCoords;" + "in vec4 aColour;" + "" + "in vec2 aWsp;" + "in vec4 aClip;" + + "void main()" + "{" + "float clip_blend = step( aWsp.x, aClip.z ) *" + "step( aWsp.y, aClip.w ) *" + "step( aClip.x, aWsp.x ) *" + "step( aClip.y, aWsp.y ); " + + "vec4 colour = texture( uTexImage, aTexCoords );" + "float value = dot(vec4(1.0),colour)*0.25;" + + "vec3 col = vec3(pow(cos(value*3.14159265*2.0)*0.5+0.5,0.5))" + "* vec3(step(value,0.5),0.3,step(1.0-value,0.5));" + + "FragColor = vec4( col*4.0, clip_blend );" + "}" + } +}; + typedef i16 ui_px; typedef u32 ui_colour; typedef ui_px ui_rect[4]; @@ -159,7 +219,7 @@ struct } static vg_uictx; -#define UI_GLYPH_SPACING_X 9 +#define UI_GLYPH_SPACING_X 8 static GLuint ui_glyph_texture = 0; static ui_colourset ui_default_colours = { @@ -170,7 +230,8 @@ static ui_colourset ui_default_colours = { VG_STATIC void _vg_ui_init(void) { - if( !vg_shader_compile( &_shader_ui ) ) + if( !vg_shader_compile( &_shader_ui ) || + !vg_shader_compile( &_shader_ui_image ) ) vg_fatal_exit_loop( "Failed to compile ui shader" ); /* @@ -180,6 +241,7 @@ VG_STATIC void _vg_ui_init(void) vg_uictx.max_indices = 20000; vg_uictx.max_verts = 30000; + vg_uictx.colours = &ui_default_colours; /* Generate the buffer we are gonna be drawing to */ glGenVertexArrays( 1, &vg_uictx.vao ); @@ -227,7 +289,7 @@ VG_STATIC void _vg_ui_init(void) /* Alloc RAM default context */ u32 vert_size = vg_uictx.max_verts*sizeof(struct ui_vert), - inds_size = vg_uictx.max_indices*sizeof(u16); + inds_size = vg_align8( vg_uictx.max_indices*sizeof(u16) ); vg_uictx.vertex_buffer = vg_linear_alloc( vg_mem.rtmemory, vert_size ); vg_uictx.indice_buffer = vg_linear_alloc( vg_mem.rtmemory, inds_size ); @@ -238,7 +300,7 @@ VG_STATIC void _vg_ui_init(void) /* Load default font */ u32 compressed[] = { - #include "vg/vg_pxfont.h" + #include "vg/vg_pxfont_thin.h" }; u32 pixels = 0, total = 256*256, data = 0; @@ -321,6 +383,15 @@ VG_STATIC void ui_draw( m3x3f view_override ) glDrawElements( GL_TRIANGLES, num_indices_normal, GL_UNSIGNED_SHORT, (void*)(0) ); + + + /* images */ + glUseProgram( _shader_ui_image.id ); + glUniformMatrix3fv( glGetUniformLocation( _shader_ui_image.id, "uPv" ), 1, + GL_FALSE, (float *)view_override ); + + glActiveTexture( GL_TEXTURE1 ); + glUniform1i( glGetUniformLocation( _shader_ui_image.id, "uTexImage" ), 1 ); /* Draw image elements */ for( int i = 0; i < vg_uictx.image_count; i ++ )