add some circle indicators
authorhgn <hgodden00@gmail.com>
Sat, 25 Sep 2021 19:58:44 +0000 (20:58 +0100)
committerhgn <hgodden00@gmail.com>
Sat, 25 Sep 2021 19:58:44 +0000 (20:58 +0100)
fishladder.c
vg/vg.h
vg/vg_m.h

index 287a1ea3d6d1c3f61ea1ff322c887cc7c8cd523c..6929cffb9a8b2eab9ca77417c795efb9a54fc3e9 100644 (file)
@@ -8,11 +8,11 @@ SHADER_DEFINE( shader_tile_colour,
        // VERTEX
        "layout (location=0) in vec2 a_co;"
        "uniform mat3 uPv;"
-       "uniform vec2 uOffset;"
+       "uniform vec3 uOffset;"
        ""
        "void main()"
        "{"
-               "gl_Position = vec4( uPv * vec3( a_co + uOffset, 1.0 ), 1.0 );"
+               "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
        "}",
        
        // FRAGMENT
@@ -64,6 +64,8 @@ struct world
        
        GLuint tile_vao;
        GLuint tile_vbo;
+       GLuint circle_vao;
+       GLuint circle_vbo;
        
        int selected;
 } world = {};
@@ -216,36 +218,78 @@ void vg_register(void)
 
 void vg_start(void)
 {
-       glGenVertexArrays( 1, &world.tile_vao );
-       glGenBuffers( 1, &world.tile_vbo );
-       
-       float quad_mesh[] =
+       // Quad mesh
        {
-               0.05f, 0.05f, 0.05f, 0.95f, 0.95f, 0.95f,
-               0.05f, 0.05f, 0.95f, 0.95f, 0.95f, 0.05f,
+               glGenVertexArrays( 1, &world.tile_vao );
+               glGenBuffers( 1, &world.tile_vbo );
                
-               0.48f, 0.48f, 0.5f, 0.52f, 0.52f, 0.52f, // Static dot
-               0.375f, 0.25f, 0.5f, 0.75f, 0.625f, 0.25f, // Downwards pointing arrow
-               0.25f, 0.625f, 0.75f, 0.5f, 0.25f, 0.375f, // Left
-               0.625f, 0.75f, 0.5f, 0.25f, 0.375f, 0.75f, // up
-               0.75f, 0.375f, 0.25f, 0.5f, 0.75f, 0.625f
+               float quad_mesh[] =
+               {
+                       0.01f, 0.01f, 0.01f, 0.99f, 0.99f, 0.99f,
+                       0.01f, 0.01f, 0.99f, 0.99f, 0.99f, 0.01f,
+                       
+                       0.48f, 0.48f, 0.5f, 0.52f, 0.52f, 0.52f, // Static dot
+                       0.375f, 0.25f, 0.5f, 0.75f, 0.625f, 0.25f, // Downwards pointing arrow
+                       0.25f, 0.625f, 0.75f, 0.5f, 0.25f, 0.375f, // Left
+                       0.625f, 0.75f, 0.5f, 0.25f, 0.375f, 0.75f, // up
+                       0.75f, 0.375f, 0.25f, 0.5f, 0.75f, 0.625f
+               };
                
-       };
-       
-       glBindVertexArray( world.tile_vao );
-       glBindBuffer( GL_ARRAY_BUFFER, world.tile_vbo );
-       glBufferData
-       (
-               GL_ARRAY_BUFFER,
-               sizeof( quad_mesh ),
-               quad_mesh,
-               GL_STATIC_DRAW
-       );
+               glBindVertexArray( world.tile_vao );
+               glBindBuffer( GL_ARRAY_BUFFER, world.tile_vbo );
+               glBufferData
+               (
+                       GL_ARRAY_BUFFER,
+                       sizeof( quad_mesh ),
+                       quad_mesh,
+                       GL_STATIC_DRAW
+               );
+               
+               glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0 );
+               glEnableVertexAttribArray( 0 );
+               
+               VG_CHECK_GL();
+       }
        
-       glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0 );
-       glEnableVertexAttribArray( 0 );
+       // Circle mesh
+       {
+               glGenVertexArrays( 1, &world.circle_vao );
+               glGenBuffers( 1, &world.circle_vbo );
        
-       VG_CHECK_GL();  
+               float circle_mesh[32*6*3];
+               int res = vg_list_size( circle_mesh ) / (6*3);
+
+               for( int i = 0; i < res; i ++ )
+               {
+                       v2f v0 = { sinf( ((float)i/(float)res)*VG_TAUf ), cosf( ((float)i/(float)res)*VG_TAUf ) };
+                       v2f v1 = { sinf( ((float)(i+1)/(float)res)*VG_TAUf ), cosf( ((float)(i+1)/(float)res)*VG_TAUf ) };
+               
+                       circle_mesh[ i*6+0 ] = 0.0f;
+                       circle_mesh[ i*6+1 ] = 0.0f;
+                       
+                       v2_copy( v0, circle_mesh + 32*6 + i*12 );
+                       v2_muls( v0, 0.8f, circle_mesh + 32*6 + i*12+2 );
+                       v2_copy( v1, circle_mesh + 32*6 + i*12+4 );
+                       
+                       v2_copy( v1, circle_mesh + 32*6 + i*12+6 );
+                       v2_muls( v1, 0.8f, circle_mesh + 32*6 + i*12+8 );
+                       v2_muls( v0, 0.8f, circle_mesh + 32*6 + i*12+10 );
+                       
+                       v2_copy( v0, circle_mesh + i*6+4 );
+                       v2_copy( v1, circle_mesh + i*6+2 );
+                       v2_copy( v0, circle_mesh+i*6+4 );
+                       v2_copy( v1, circle_mesh+i*6+2 );
+               }
+               
+               glBindVertexArray( world.circle_vao );
+               glBindBuffer( GL_ARRAY_BUFFER, world.circle_vbo );
+               glBufferData( GL_ARRAY_BUFFER, sizeof( circle_mesh ), circle_mesh, GL_STATIC_DRAW );
+               
+               glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0 );
+               glEnableVertexAttribArray( 0 );
+               
+               VG_CHECK_GL();
+       }
        
        map_load
        ( 
@@ -266,7 +310,10 @@ void vg_free(void)
 {
        glDeleteVertexArrays( 1, &world.tile_vao );
        glDeleteBuffers( 1, &world.tile_vbo );
-       
+
+       glDeleteVertexArrays( 1, &world.circle_vao );
+       glDeleteBuffers( 1, &world.circle_vbo );
+
        map_free();
 }
 
@@ -581,7 +628,7 @@ void vg_render(void)
        {
                for( int x = 0; x < world.w; x ++ )
                {
-                       glUniform2f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x, (float)y );
+                       glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x, (float)y, 1.0f );
                        
                        v4f colour;
                        
@@ -589,12 +636,12 @@ void vg_render(void)
                        
                        if( cell->state & FLAG_WALL ) { v4_copy( (v4f){ 0.2f, 0.2f, 0.2f, 1.0f }, colour ); }
                        else if( cell->state & FLAG_CANAL ) { v4_copy( (v4f){ 0.6f, 0.6f, 0.6f, 1.0f }, colour ); }
-                       else if( cell->state & FLAG_INPUT ) { v4_copy( (v4f){ 0.2f, 0.3f, 0.7f, 1.0f }, colour ); }
+                       else if( cell->state & FLAG_INPUT ) { v4_copy( (v4f){ 0.5f, 0.5f, 0.5f, 1.0f }, colour ); }
                        else if( cell->state & FLAG_OUTPUT ) { v4_copy( (v4f){ 0.2f, 0.7f, 0.3f, 1.0f }, colour ); }
                        else v4_copy( (v4f){ 0.9f, 0.9f, 0.9f, 1.0f }, colour );
                        
                        if( cell->water[world.frame&0x1] )
-                               v4_copy( (v4f){ 0.2f, 0.3f, 0.7f * (float)(cell->water[world.frame&0x1]) * (1.0f/8.0f), 1.0f }, colour );
+                               v4_copy( (v4f){ 0.2f, 0.3f, 0.7f * (float)(cell->water[world.frame&0x1]) * (1.0f/16.0f), 1.0f }, colour );
                        
                        if( world.selected == y*world.w + x )
                                v3_muls( colour, sinf( vg_time )*0.25f + 0.5f, colour );
@@ -615,6 +662,24 @@ void vg_render(void)
                        }
                }
        }
+       
+       glBindVertexArray( world.circle_vao );
+       
+       // Draw i/o arrays
+       for( int i = 0; i < arrlen( world.io ); i ++ )
+       {
+               struct cell_terminal *term = &world.io[ i ];
+               int posx = term->id % world.w;
+               int posy = (term->id - posx)/world.w;
+               int is_input = world.data[ term->id ].state & FLAG_INPUT;
+               
+               for( int j = 0; j < arrlen( term->conditions ); j ++ )
+               {
+                       glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)posx + 0.2f + 0.2f * (float)j, (float)posy + 0.2f, 0.1f );
+                       glUniform4f( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 0.2f, 0.8f, 0.6f, 1.0f );
+                       glDrawArrays( GL_TRIANGLES, is_input? 0: 32*3, is_input? 32*3: 32*6 );
+               }
+       }
 }
 
 void vg_ui(void){}
diff --git a/vg/vg.h b/vg/vg.h
index a7e520546e7f18530d68eb477f741f79682e3ff8..6c093d72c15e7926ebade90979307455307a1a16 100644 (file)
--- a/vg/vg.h
+++ b/vg/vg.h
@@ -284,7 +284,7 @@ static void vg_init( int argc, char *argv[], const char *window_name )
        glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
        glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE );
        
-       glfwWindowHint( GLFW_SAMPLES, 1 );
+       glfwWindowHint( GLFW_SAMPLES, 4 );
        
        GLFWmonitor *monitor_primary = glfwGetPrimaryMonitor();
        
index de9cb6dd3713dc837f12b726e678634ab614d13d..27481ae995db9b3aca8694ffea139671e9f27438 100644 (file)
--- a/vg/vg_m.h
+++ b/vg/vg_m.h
@@ -3,7 +3,8 @@
 // Util
 // ==================================================================================================================
 
-#define VG_PIf 3.14159265358979323846264338327950288f
+#define VG_PIf  3.14159265358979323846264338327950288f
+#define VG_TAUf 6.28318530717958647692528676655900576f
 
 // Simple min/max replacements
 static inline float vg_minf( float a, float b )