dont remember what i did
authorhgn <hgodden00@gmail.com>
Mon, 1 Nov 2021 16:45:23 +0000 (16:45 +0000)
committerhgn <hgodden00@gmail.com>
Mon, 1 Nov 2021 16:45:23 +0000 (16:45 +0000)
fishladder.c
fishladder_resources.h
textures/background.png [new file with mode: 0644]
textures/tileset.png
textures/wood.png

index f4afab1714af2a915a1167a278329867e49ad901..f75188ee6e1b18b9562af20fbacafb6d5f650f1c 100644 (file)
@@ -571,15 +571,20 @@ void vg_update(void)
                vg_info( "Stopping simulation!\n" );
        }
        
-       float ratio = (float)vg_window_y / (float)vg_window_x;
-       float const size = 9.5f;
+       // Fit within screen
+
+       float r1 = (float)vg_window_y / (float)vg_window_x,
+                       r2 = (float)world.h / (float)world.w,
+                       size;
+       
+       size = ( r2 < r1? (float)world.w * 0.5f: ((float)world.h * 0.5f) / r1 ) + 2.5f; 
+       m3x3_projection( m_projection, -size, size, -size*r1, size*r1 );
        
        v3f origin;
-       origin[0] = -0.5f * world.w;
-       origin[1] = -0.5f * world.h;
+       origin[0] = floorf( -0.5f * world.w );
+       origin[1] = floorf( -0.5f * world.h );
        origin[2] = 0.0f;
        
-       m3x3_projection( m_projection, -size, size, -size*ratio, size*ratio );
        m3x3_identity( m_view );
        m3x3_translate( m_view, origin );
        m3x3_mul( m_projection, m_view, vg_pv );
@@ -946,7 +951,7 @@ static void render_tiles( v2i start, v2i end, v4f const regular_colour, v4f cons
                        {
                                uv[0] = tile_offsets[ cell->config ][0];
                                uv[1] = tile_offsets[ cell->config ][1];
-                       }
+                       } else continue;
                        
                        glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), (float)x, (float)y, uv[0], uv[1] );
                        if( selected )
@@ -966,7 +971,7 @@ void vg_render(void)
        glViewport( 0,0, vg_window_x, vg_window_y );
 
        glDisable( GL_DEPTH_TEST );
-       glClearColor( 0.8f, 0.8f, 0.8f, 1.0f );
+       glClearColor( 0.369768f, 0.3654f, 0.42f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        
        v4f const colour_default = {1.0f, 1.0f, 1.0f, 1.0f};
@@ -982,6 +987,23 @@ void vg_render(void)
 
        use_mesh( &world.tile );
        
+       // Draw background
+       
+       if(0){
+       
+       SHADER_USE( shader_background );
+       glUniformMatrix3fv( SHADER_UNIFORM( shader_background, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
+       
+       vg_tex2d_bind( &tex_background, 0 );
+       glUniform1i( SHADER_UNIFORM( shader_background, "uTexMain" ), 0 );
+       
+       glUniform3f( SHADER_UNIFORM( shader_background, "uOffset" ), -50, -50, 100 );
+       
+       draw_mesh( 0, 2 );
+
+       }
+       
+       
        SHADER_USE( shader_tile_main );
 
        m2x2f subtransform;
@@ -989,6 +1011,11 @@ void vg_render(void)
        glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main, "uSubTransform" ), 1, GL_FALSE, (float *)subtransform );  
        glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_main, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
        glUniform1f( SHADER_UNIFORM( shader_tile_main, "uGhost" ), 0.0f );
+       glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 0.0f );
+       
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glBlendEquation(GL_FUNC_ADD);
        
        // Bind textures
        vg_tex2d_bind( &tex_tile_data, 0 );
@@ -999,9 +1026,7 @@ void vg_render(void)
        
        render_tiles( NULL, NULL, colour_default, colour_default );
        
-       glEnable(GL_BLEND);
-       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       glBlendEquation(GL_FUNC_ADD);
+
        
        SHADER_USE( shader_ball );
        glUniformMatrix3fv( SHADER_UNIFORM( shader_ball, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
@@ -1040,6 +1065,7 @@ void vg_render(void)
        vg_tex2d_bind( &tex_wood, 1 );
        glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 );
        
+       glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 1.0f );
        render_tiles( NULL, NULL, colour_default, colour_selected  );
 
        //      Draw splitters
index 1f8c5454da860017005ac429a71fd2353df94cb3..00cb199a780b3334f02ed0eb9201c46fc7939d0a 100644 (file)
@@ -5,8 +5,9 @@ vg_tex2d tex_tile_data =        { .path = "textures/tileset.png" };
 vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.png" };
 vg_tex2d tex_wood =                    { .path = "textures/wood.png" };
 vg_tex2d tex_ball =                    { .path = "textures/ball.png", .flags = VG_TEXTURE_CLAMP };
+vg_tex2d tex_background =      { .path = "textures/background.png" };
 
-vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball };
+vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball, &tex_background };
 
 // AUDIO
 // ===========================================================================================================
@@ -209,6 +210,7 @@ SHADER_DEFINE( shader_tile_main,
        "uniform sampler2D uTexGlyphs;"
        "uniform sampler2D uTexWood;"
        "uniform float uGhost;"
+       "uniform float uForeground;"
        "uniform vec2 uMousePos;"
        "uniform vec4 uColour;"
        ""
@@ -225,7 +227,7 @@ SHADER_DEFINE( shader_tile_main,
                
                "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
                
-               "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );"
+               "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );"
                
                "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
                "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
@@ -233,7 +235,46 @@ SHADER_DEFINE( shader_tile_main,
                "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
        "}"
        ,
-       UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" })
+       UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour", "uForeground" })
+)
+
+SHADER_DEFINE( shader_background,
+       // VERTEX
+       "layout (location=0) in vec2 a_co;"
+       "uniform mat3 uPv;"
+       "uniform vec3 uOffset;"
+       ""
+       "out vec2 aTexCoords;"
+       ""
+       "void main()"
+       "{"
+               "vec2 world_pos = a_co * uOffset.z + uOffset.xy;"
+               "gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );"
+               "aTexCoords = world_pos * 0.25;"
+       "}",
+       
+       // FRAGMENT
+       "out vec4 FragColor;"
+       ""
+       "uniform sampler2D uTexMain;"
+       ""
+       "in vec2 aTexCoords;"
+       ""
+       "vec2 hash22(vec2 p)"
+       "{"
+               "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
+               "p3 += dot(p3, p3.yzx+33.33);"
+               "return fract((p3.xx+p3.yz)*p3.zy);"
+       "}"
+       ""
+       "void main()"
+       "{"
+               "vec2 random_offset = floor( hash22( floor( aTexCoords * 4.0 ) ) * 4.0 ) * 0.25;"
+               "vec4 background = texture( uTexMain, aTexCoords );"
+               "FragColor = vec4( background.rgb * (1.0+random_offset.r*0.015), 1.0 );"
+       "}"
+       ,
+       UNIFORMS({ "uPv", "uOffset", "uTexMain" })
 )
 
 void vg_register(void)
@@ -241,4 +282,5 @@ void vg_register(void)
        SHADER_INIT( shader_tile_colour );
        SHADER_INIT( shader_tile_main );
        SHADER_INIT( shader_ball );
+       SHADER_INIT( shader_background );
 }
diff --git a/textures/background.png b/textures/background.png
new file mode 100644 (file)
index 0000000..7312b7c
Binary files /dev/null and b/textures/background.png differ
index aa41e19761f2904fbfb2f86592488bfe6e8cef44..6d8928b59e11be0896064eb0e02c797920ce51f2 100644 (file)
Binary files a/textures/tileset.png and b/textures/tileset.png differ
index 79521d4135c83cb23025e1fd9be1495f812e901f..81c0817eeb130627c7a8d900815bb4771890a4ef 100644 (file)
Binary files a/textures/wood.png and b/textures/wood.png differ