X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_ui.h;h=dc0cceec4288b3dbeb7365d29846e273ad72a918;hb=3d52e114a0f608e58bc99cfc6faaeb41cfcf84c7;hp=ba428b009b385132e1f5bbf3c6253b09e5b2ddf5;hpb=f54d25963e8f226982f6b269cb8c031d87014bc7;p=vg.git diff --git a/vg_ui.h b/vg_ui.h index ba428b0..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" ); /* @@ -239,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; @@ -322,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 ++ )