theme selection
authorhgn <hgodden00@gmail.com>
Tue, 18 Jan 2022 21:40:43 +0000 (21:40 +0000)
committerhgn <hgodden00@gmail.com>
Tue, 18 Jan 2022 21:40:43 +0000 (21:40 +0000)
14 files changed:
fishladder.c
fishladder_resources.h
sprites_autocombine.h
texsheet.c
textures/tile_lab.png [new file with mode: 0644]
textures/tile_minimal.png [new file with mode: 0644]
textures/tile_wood.png [new file with mode: 0644]
textures/wood.png [deleted file]
textures_combine/flare_b.png [new file with mode: 0644]
textures_combine/flare_y.png [new file with mode: 0644]
textures_combine/jack-1.png
textures_combine/jack-2.png
textures_combine/peg.png
vg/vg_tex.h

index e0cfd67458a364ea41326f5c052916e34509662c..2a2da7520751101d4ff725de383d1bdd0817622a 100644 (file)
@@ -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] = {
index 7b12859d44f94bb993c23fab06b9dd5627826e4f..d1f2210fe8b08d0362a676427627a3372507e7af 100644 (file)
@@ -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 );
 }
 
 /*
index 2808eb0586c0235c39125d3035c45efec38e5f8d..aa9e326705a9508c82e0ccbf58a1b0ccd67be250 100644 (file)
@@ -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
index f420866bd1a6dfc5ef6d9f5b033fb7e3f4bf0d97..367136bbc3e8d1d009cad32c479575e8725c5fc7 100644 (file)
@@ -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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..f802877
Binary files /dev/null and b/textures_combine/flare_y.png differ
index 7d88b8799dc051a017fabbb244deb520fa517a8a..e6f94c3d27a8958c577907d71e310939e848f715 100644 (file)
Binary files a/textures_combine/jack-1.png and b/textures_combine/jack-1.png differ
index 92488da62865fa671db2845c776c0c4ff7bd7782..9c862ac010cd236fda65e4c1b90231d8ccfd2ba7 100644 (file)
Binary files a/textures_combine/jack-2.png and b/textures_combine/jack-2.png differ
index 83b366b374f16d68dbec866f5adc6f878fe37f24..d541803fe723d9e848482b08d8775e7c789c6b90 100644 (file)
Binary files a/textures_combine/peg.png and b/textures_combine/peg.png differ
index c757b1826a42996aa643fe51259195e5d7d66c3f..4c14540ca431a4b5404534dc5d44f27938e04467 100644 (file)
@@ -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 )
 {