From: hgn Date: Tue, 18 Jan 2022 21:40:43 +0000 (+0000) Subject: theme selection X-Git-Url: https://harrygodden.com/git/?p=fishladder.git;a=commitdiff_plain;h=ec1dd5de4848534241c8bea3841ef36fe047915b theme selection --- diff --git a/fishladder.c b/fishladder.c index e0cfd67..2a2da75 100644 --- a/fishladder.c +++ b/fishladder.c @@ -399,6 +399,7 @@ m3x3f m_mdl; // =========================================================================================================== static int colour_set_id = 0; +static int world_theme_id = 0; static v3f colour_sets[][4] = { @@ -419,6 +420,31 @@ static v3f colour_sets[][4] = }, }; +static struct world_theme +{ + const char *name; + v3f colour_bg; + vg_tex2d *tex_tiles; +} +world_themes[] = +{ + { + "Wood", + {}, + &tex_tiles_wood + }, + { + "Minimal", + {}, + &tex_tiles_min + }, + { + "Lab", + {}, + &tex_tiles_lab + } +}; + static void colour_code_v3( char const cc, v3f target ) { if( cc >= 'a' && cc <= 'z' ) @@ -2540,6 +2566,16 @@ static void level_selection_buttons(void) } } +static void render_sprite( enum sprites_auto_combine_index id, v3f pos ) +{ + struct vg_sprite *sp = &sprites_auto_combine[ id ]; + + glUniform4fv( SHADER_UNIFORM( shader_sprite, "uUv" ), 1, sp->uv_xywh ); + glUniform3f( SHADER_UNIFORM( shader_sprite, "uPos" ), pos[0], pos[1], pos[2] * world.st.world_transition ); + + draw_mesh( 0, 2 ); +} + void vg_render(void) { glViewport( 0,0, vg_window_x, vg_window_y ); @@ -2557,6 +2593,8 @@ void vg_render(void) int const empty_start = circle_base+32; int const empty_count = circle_base+32*2; + struct world_theme *theme = &world_themes[ world_theme_id ]; + if( !world.initialzed ) return; @@ -2629,8 +2667,8 @@ void vg_render(void) // Bind textures vg_tex2d_bind( &tex_tile_data, 0 ); glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexGlyphs" ), 0 ); - - vg_tex2d_bind( &tex_wood, 1 ); + + vg_tex2d_bind( theme->tex_tiles, 1 ); glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 ); render_tiles( colour_default, colour_default ); @@ -2689,7 +2727,8 @@ void vg_render(void) vg_tex2d_bind( &tex_tile_data, 0 ); glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexGlyphs" ), 0 ); - vg_tex2d_bind( &tex_wood, 1 ); + // TODO: is this needed to be rebinded? + vg_tex2d_bind( theme->tex_tiles, 1 ); glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 ); glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 1.0f ); @@ -2832,6 +2871,34 @@ void vg_render(void) if( vg_get_button_up( "primary" ) ) world_button_exec( NULL, NULL, NULL, NULL ); + + // SPRITES + // ======================================================================================================== + SHADER_USE( shader_sprite ); + glUniformMatrix3fv( SHADER_UNIFORM( shader_sprite, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); + + vg_tex2d_bind( &tex_sprites, 0 ); + glUniform1i( SHADER_UNIFORM( shader_sprite, "uTexMain" ), 0 ); + + for( int i = 0; i < world.tile_special_count; i ++ ) + { + struct render_cmd *cmd = &world.cmd_buf_specials[i]; + struct cell *cell = cmd->ptr; + + if( cell->config == k_cell_type_split ) + { + v2f center = { cmd->pos[0] + 0.5f, cmd->pos[1] + 0.5f }; + + v3f p0 = { 0.0f, 0.0f, 4.0f }; + v3f p1 = { 0.0f, 0.0f, 4.0f }; + + v2_add( center, (v2f){ -0.25f, -0.25f }, p0 ); + v2_add( center, (v2f){ 0.25f, -0.25f }, p1 ); + + render_sprite( k_sprite_jack_1, p0 ); + render_sprite( k_sprite_jack_2, p1 ); + } + } // TEXT ELEMENTS // ======================================================================================================== @@ -2996,7 +3063,6 @@ void vg_render(void) // SUB SPLITTER DIRECTION // ======================================================================================================== - // TODO: Make this sprites probably glUniform4f( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 0.9f, 0.35f, 0.1f, 0.75f ); @@ -3011,12 +3077,48 @@ void vg_render(void) draw_mesh( cell->state & FLAG_FLIP_FLOP? 5: 4, 1 ); } } + + // LIGHT FLARES + // ======================================================================================================== + glBlendFunc(GL_ONE, GL_ONE); + glBlendEquation(GL_FUNC_ADD); + + SHADER_USE( shader_sprite ); + + vg_tex2d_bind( &tex_sprites, 0 ); + glUniform1i( SHADER_UNIFORM( shader_sprite, "uTexMain" ), 0 ); + for( int i = 0; i < world.tile_special_count; i ++ ) + { + struct render_cmd *cmd = &world.cmd_buf_specials[i]; + struct cell *cell = cmd->ptr; + + if( cell->config == k_cell_type_split ) + { + v2f center = { cmd->pos[0] + 0.5f, cmd->pos[1] + 0.5f }; + + v3f p0 = { 0.0f, 0.0f, 12.0f }; + v3f p1 = { 0.0f, 0.0f, 12.0f }; + + v2_add( center, (v2f){ -0.25f, -0.25f }, p0 ); + v2_add( center, (v2f){ 0.25f, -0.25f }, p1 ); + + if( cell->state & FLAG_FLIP_FLOP ) + render_sprite( k_sprite_flare_y, p1 ); + else + render_sprite( k_sprite_flare_b, p0 ); + } + } + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + // I/O ARRAYS // ======================================================================================================== //glEnable(GL_BLEND); - + SHADER_USE( shader_tile_colour ); + for( int i = 0; i < arrlen( world.io ); i ++ ) { struct cell_terminal *term = &world.io[ i ]; @@ -3476,6 +3578,14 @@ void vg_start(void) .persistent = 1 }); + vg_convar_push( (struct vg_convar){ + .name = "theme", + .data = &world_theme_id, + .data_type = k_convar_dtype_i32, + .opt_i32 = { .min = 0, .max = vg_list_size( world_themes )-1, .clamp = 1 }, + .persistent = 1, + }); + // Combined quad, long quad / empty circle / filled circle mesh { float combined_mesh[6*6 + 32*6*3] = { diff --git a/fishladder_resources.h b/fishladder_resources.h index 7b12859..d1f2210 100644 --- a/fishladder_resources.h +++ b/fishladder_resources.h @@ -119,14 +119,30 @@ vg_tex2d tex_ubuntu = { .path = "textures/ubuntu.qoi" }; vg_tex2d tex_tile_data = { .path = "textures/tileset.qoi" }; vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.qoi" }; -vg_tex2d tex_wood = { .path = "textures/wood.qoi" }; + +vg_tex2d tex_tiles_wood = { .path = "textures/tile_wood.qoi" }; +vg_tex2d tex_tiles_min = { .path = "textures/tile_minimal.qoi" }; +vg_tex2d tex_tiles_lab = { .path = "textures/tile_lab.qoi" }; + vg_tex2d tex_ball_noise = { .path = "textures/bnoise.qoi" }; vg_tex2d tex_monofur = { .path = "textures/ascii.qoi", .flags = VG_TEXTURE_NO_MIP }; vg_tex2d tex_unkown = { .path = "textures/unkown.qoi" }; vg_tex2d tex_buttons = { .path = "textures/buttons.qoi" }; vg_tex2d tex_sprites = { .path = "textures/autocombine.qoi" }; -vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball_noise, &tex_monofur, &tex_unkown, &tex_buttons, &tex_ubuntu, &tex_sprites }; +vg_tex2d *texture_list[] = { + &tex_tile_detail, + &tex_tile_data, + &tex_tiles_wood, + &tex_tiles_min, + &tex_tiles_lab, + &tex_ball_noise, + &tex_monofur, + &tex_unkown, + &tex_buttons, + &tex_ubuntu, + &tex_sprites +}; #include "sprites_autocombine.h" @@ -350,7 +366,8 @@ SHADER_DEFINE( shader_ball, "float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);" "vec3 marble_comp = uColour*0.9 + (noise_sample.x*0.7+pow(rim_light,3.0)*2.0) * 0.1;" - "vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );" + //"vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );" + "vec4 colour_comp = mix( vec4(0.2,0.2,0.2,shadow), vec4(marble_comp,1.0), circle_factor );" "FragColor = colour_comp;" "}" @@ -408,13 +425,16 @@ SHADER_DEFINE( shader_tile_main, "" "void main()" "{" - "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;" + //"vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;" + "vec3 shadowing_colour = vec3( 0.8, 0.8, 0.8 );" + "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );" "vec4 wood = texture( uTexWood, aTexCoords.zw );" "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );" "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );" - "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );" + //"vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );" + "vec3 shadows = mix( shadowing_colour, vec3(1.0,1.0,1.0), glyph.r );" "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );" @@ -618,8 +638,8 @@ SHADER_DEFINE( shader_sprite, // VERTEX "layout (location=0) in vec2 a_co;" // quad mesh - "layout (location=1) in vec4 ins_uv;" // instanced data (uv) - "layout (location=2) in vec3 ins_pos;" // position + scale + "uniform vec4 uUv;" + "uniform vec3 uPos;" "" "uniform mat3 uPv;" "" @@ -627,25 +647,24 @@ SHADER_DEFINE( shader_sprite, "" "void main()" "{" - "vec2 vertex_world = ins_uv.zw * a_co * ins_pos.z + ins_pos.xy;" + "vec2 vertex_world = uUv.zw * (a_co-0.5) * uPos.z + uPos.xy;" "gl_Position = vec4( uPv * vec3( vertex_world, 1.0 ), 1.0 );" - "aTexCoords = ins_uv.xy + (a_co+0.5)*ins_uv.zw;" + "aTexCoords = uUv.xy + a_co*uUv.zw;" "}", // FRAGMENT "uniform sampler2D uTexMain;" - "uniform vec4 uColour;" "out vec4 FragColor;" "" "in vec2 aTexCoords;" "" "void main()" "{" - "vec4 glyph = texture( uTexGlyphs, aTexCoords );" - "FragColor = glyph;" + "vec4 texture_sample = texture( uTexMain, aTexCoords );" + "FragColor = texture_sample;" "}" , - UNIFORMS({ "uPv", "uTexMain", "uColour" }) + UNIFORMS({ "uPv", "uTexMain", "uUv", "uPos" }) ) void vg_register(void) @@ -657,6 +676,7 @@ void vg_register(void) SHADER_INIT( shader_wire ); SHADER_INIT( shader_buttons ); SHADER_INIT( shader_sdf ); + SHADER_INIT( shader_sprite ); } /* diff --git a/sprites_autocombine.h b/sprites_autocombine.h index 2808eb0..aa9e326 100644 --- a/sprites_autocombine.h +++ b/sprites_autocombine.h @@ -1,6 +1,8 @@ -static enum sprites_auto_combine_index +enum sprites_auto_combine_index { k_sprite_donut, + k_sprite_flare_b, + k_sprite_flare_y, k_sprite_jack_1, k_sprite_jack_2, k_sprite_peg, @@ -8,8 +10,10 @@ static enum sprites_auto_combine_index static struct vg_sprite sprites_auto_combine[] = { - { 0, 0, 8192, 8192 }, - { 8192, 0, 4096, 4096 }, - { 12288, 0, 4096, 4096 }, - { 16384, 0, 4096, 4096 }, + {{ 0.000000, 0.000000, 0.125000, 0.125000 }}, + {{ 0.125000, 0.000000, 0.125000, 0.125000 }}, + {{ 0.250000, 0.000000, 0.125000, 0.125000 }}, + {{ 0.375000, 0.000000, 0.062500, 0.062500 }}, + {{ 0.437500, 0.000000, 0.062500, 0.062500 }}, + {{ 0.500000, 0.000000, 0.062500, 0.062500 }} }; \ No newline at end of file diff --git a/texsheet.c b/texsheet.c index f420866..367136b 100644 --- a/texsheet.c +++ b/texsheet.c @@ -47,7 +47,7 @@ int main( int argc, const char *argv[] ) return 0; } - fprintf( fp, "static enum %s_index\n{\n", argv[3] ); + fprintf( fp, "enum %s_index\n{\n", argv[3] ); // Load images // ----------- @@ -109,13 +109,12 @@ int main( int argc, const char *argv[] ) u8 *dest = (u8 *)malloc( 1024*1024*4 ); - // Clear (temp) for( int i = 0; i < 1024*1024; i ++ ) { dest[ i*4 + 0 ] = 0; dest[ i*4 + 1 ] = 0; - dest[ i*4 + 2 ] = 128; - dest[ i*4 + 3 ] = 255; + dest[ i*4 + 2 ] = 0; + dest[ i*4 + 3 ] = 0; } struct region @@ -132,8 +131,6 @@ int main( int argc, const char *argv[] ) }; int stack_h = 0; - int sf = 64; - for( int i = 0; i < num_images; i ++ ) { struct image_src *psrc = &source_images[ i ]; @@ -146,13 +143,18 @@ int main( int argc, const char *argv[] ) if( (pregion->p0[ 0 ] + psrc->x <= pregion->p1[0]) && (pregion->p0[ 1 ] + psrc->y <= pregion->p1[1]) ) { // Passed, add image and create subdivisions - fprintf( fp, "\t{ %hu, %hu, %hu, %hu },\n", - (u16)(sf * pregion->p0[0]), - (u16)(sf * pregion->p0[1]), - (u16)(sf * psrc->x), - (u16)(sf * psrc->y) + fprintf( fp, "\t{{ %f, %f, %f, %f }}", + (float)pregion->p0[0] / 1024.0f, + (float)pregion->p0[1] / 1024.0f, + (float)psrc->x / 1024.0f, + (float)psrc->y / 1024.0f ); + if( i != num_images-1 ) + fputs( ",\n", fp ); + else + fputc( '\n', fp ); + // Write image for( int y = 0; y < psrc->y; y ++ ) { diff --git a/textures/tile_lab.png b/textures/tile_lab.png new file mode 100644 index 0000000..638f727 Binary files /dev/null and b/textures/tile_lab.png differ diff --git a/textures/tile_minimal.png b/textures/tile_minimal.png new file mode 100644 index 0000000..5e431ac Binary files /dev/null and b/textures/tile_minimal.png differ diff --git a/textures/tile_wood.png b/textures/tile_wood.png new file mode 100644 index 0000000..81c0817 Binary files /dev/null and b/textures/tile_wood.png differ diff --git a/textures/wood.png b/textures/wood.png deleted file mode 100644 index 81c0817..0000000 Binary files a/textures/wood.png and /dev/null differ diff --git a/textures_combine/flare_b.png b/textures_combine/flare_b.png new file mode 100644 index 0000000..55ce155 Binary files /dev/null and b/textures_combine/flare_b.png differ diff --git a/textures_combine/flare_y.png b/textures_combine/flare_y.png new file mode 100644 index 0000000..f802877 Binary files /dev/null and b/textures_combine/flare_y.png differ diff --git a/textures_combine/jack-1.png b/textures_combine/jack-1.png index 7d88b87..e6f94c3 100644 Binary files a/textures_combine/jack-1.png and b/textures_combine/jack-1.png differ diff --git a/textures_combine/jack-2.png b/textures_combine/jack-2.png index 92488da..9c862ac 100644 Binary files a/textures_combine/jack-2.png and b/textures_combine/jack-2.png differ diff --git a/textures_combine/peg.png b/textures_combine/peg.png index 83b366b..d541803 100644 Binary files a/textures_combine/peg.png and b/textures_combine/peg.png differ diff --git a/vg/vg_tex.h b/vg/vg_tex.h index c757b18..4c14540 100644 --- a/vg/vg_tex.h +++ b/vg/vg_tex.h @@ -12,12 +12,10 @@ struct vg_tex2d GLuint name; }; -#pragma pack(push,1) struct vg_sprite { - u16 uvx, uvy, w, h; + v4f uv_xywh; }; -#pragma pack(pop) static void vg_tex2d_bind( vg_tex2d *tex, u32 id ) {