theme selection
[fishladder.git] / fishladder.c
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] = {