- 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
- 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-
- // Padding
- 0.0f, 0.0f, 0.0f, 0.0f
- };
-
- glBindVertexArray( tile_vao );
- glBindBuffer( GL_ARRAY_BUFFER, 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();
-
- // Create map buffers
- glGenVertexArrays( 1, &map.tiles_vao );
- glGenBuffers( 1, &map.tiles_vbo );
-
- glBindVertexArray( map.tiles_vao );
- glBindBuffer( GL_ARRAY_BUFFER, map.tiles_vbo );
- glBufferData( GL_ARRAY_BUFFER,
- sizeof( quad_mesh ) +
- sizeof( float )*2 * 1024 +
- sizeof( u8 )*4 * 1024,
- NULL,
- GL_DYNAMIC_DRAW
- );
-
- glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof( quad_mesh ), quad_mesh );
-
- // Base quad
- glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), (void*)0 );
- glEnableVertexAttribArray( 0 );
-
- // Offset, data arrays (instancing)
- glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), (void*)(sizeof(quad_mesh)) );
- glEnableVertexAttribArray( 1 );
- glVertexAttribDivisor( 1, 1 );
-
- glVertexAttribPointer( 2, 4, GL_UNSIGNED_BYTE, GL_FALSE, 4, (void*)(sizeof(quad_mesh)+sizeof(float)*2*1024) );
- glEnableVertexAttribArray( 2 );
- glVertexAttribDivisor( 2, 1 );
-
- map.tile_texture = vg_tex2d_rgba( "textures/rivertiles_flowm.tga" );
- vg_tex2d_nearest();
- vg_tex2d_repeat();
-
- map.flow_texture = vg_tex2d_rgba( "textures/rivertiles_ripple.tga" );
- vg_tex2d_nearest();
- vg_tex2d_repeat();
-
- fish_texture = vg_tex2d_rgba( "textures/fishe_swim.tga" );
- vg_tex2d_nearest();
- vg_tex2d_repeat();
-
- map_load
- (
- "##-#####-##;aaa,aa\n"
- "# #;\n"
- "# #;\n"
- "# #;\n"
- "# #;\n"
- "# #;\n"
- "# #;\n"
- "##+#####+##;aa,aaa\n"
- );
-}
-
-void vg_free(void)
-{
- map_free();
-
- glDeleteVertexArrays( 1, &tile_vao );
- glDeleteVertexArrays( 1, &map.tiles_vao );
-
- glDeleteBuffers( 1, &tile_vbo );
- glDeleteBuffers( 1, &map.tiles_vbo );
-
- glDeleteTextures( 1, &map.tile_texture );
- glDeleteTextures( 1, &map.flow_texture );
+ for( int x = 0; x < world.w; x ++ )
+ {
+ glUniform2f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x, (float)y );
+
+ v4f colour;
+
+ struct cell *cell = &world.data[y*world.w+x];
+
+ 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_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 );
+
+ if( world.selected == y*world.w + x )
+ v3_muls( colour, sinf( vg_time )*0.25f + 0.5f, colour );
+
+ if( cell->state & (FLAG_DROP|FLAG_SPLIT) )
+ v4_copy( (v4f){ 0.75f, 0.75f, 0.02f, 1.0f }, colour );
+
+ glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, colour );
+
+ glDrawArrays( GL_TRIANGLES, 0, 6 );
+ }
+ }