create info buffer
[fishladder.git] / fishladder.c
index f4afab1714af2a915a1167a278329867e49ad901..1bc0d5cf02591af208d25bb2cb997cadba0fc6ff 100644 (file)
@@ -190,6 +190,8 @@ struct world
        
        struct mesh tile, circle;
        
+       GLuint background_data;
+       
        int selected, tile_x, tile_y;
        v2f tile_pos;
        
@@ -403,6 +405,12 @@ void vg_start(void)
                init_mesh( &world.circle, circle_mesh, vg_list_size( circle_mesh ) );
        }
        
+       // Create info data texture
+       glGenTextures( &world.background_data );
+       glBindTexture( GL_TEXTURE_2D, texture_name );
+       glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
+       vg_tex2d_nearest();
+       
        resource_load_main();
        
        map_load( level_pack[ 0 ] );
@@ -571,15 +579,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 +959,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 +979,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 +995,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 +1019,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 +1034,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 +1073,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
@@ -1170,5 +1204,4 @@ void vg_render(void)
 void vg_ui(void)
 {
        //ui_test();
-       sfx_internal_debug_overlay();
 }