//#define VG_STEAM
#include "vg/vg.h"
-SHADER_DEFINE( colour_shader,
+SHADER_DEFINE( shader_tile_colour,
// VERTEX
- "layout (location=0) in vec3 a_co;"
- "uniform mat4 uPvm;"
+ "layout (location=0) in vec2 a_co;"
+ "uniform mat3 uPv;"
+ "uniform vec2 uOffset;"
""
"void main()"
"{"
- " vec4 vert_pos = uPvm * vec4( a_co, 1.0 );"
- " gl_Position = vert_pos;"
+ "gl_Position = vec4( uPv * vec3( a_co + uOffset, 1.0 ), 1.0 );"
"}",
// FRAGMENT
""
"void main()"
"{"
- " FragColor = uColour;"
+ "FragColor = uColour;"
"}"
,
- UNIFORMS({ "uPvm", "uColour" })
+ UNIFORMS({ "uPv", "uOffset", "uColour" })
)
+m3x3f m_projection;
+m3x3f m_view;
+m3x3f m_mdl;
+
+struct world
+{
+ struct cell
+ {
+ u32 state;
+ }
+ *data;
+
+ u32 w, h;
+
+ GLuint tile_vao;
+ GLuint tile_vbo;
+} world = { .w = 4, .h = 4 };
+
int main( int argc, char *argv[] )
{
vg_init( argc, argv, "FishLadder" );
}
-void vg_start(void)
+void vg_register(void)
{
- SHADER_INIT( colour_shader );
+ SHADER_INIT( shader_tile_colour );
}
-void vg_update(void)
+void vg_start(void)
{
-
+ glGenVertexArrays( 1, &world.tile_vao );
+ glGenBuffers( 1, &world.tile_vbo );
+
+ float 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
+ };
+
+ 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();
}
-void vg_render(void)
+void vg_free(void)
{
-
+ glDeleteVertexArrays( 1, &world.tile_vao );
+ glDeleteBuffers( 1, &world.tile_vbo );
}
-void vg_ui(void)
+void vg_update(void)
{
+ float ratio = (float)vg_window_y / (float)vg_window_x;
+ float const size = 7.5f;
+ m3x3_projection( m_projection, -size, size, size*ratio, -size*ratio );
+ m3x3_identity( m_view );
+ m3x3_translate( m_view, (v3f){ -0.5f * world.w, -0.5f * world.h } );
+ m3x3_mul( m_projection, m_view, vg_pv );
+ vg_projection_update();
}
-void vg_free(void)
+void vg_render(void)
{
+ glViewport( 0,0, vg_window_x, vg_window_y );
+
+ glDisable( GL_DEPTH_TEST );
+ glClearColor( 0.01f, 0.01f, 0.01f, 1.0f );
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glBindVertexArray( world.tile_vao );
+ SHADER_USE( shader_tile_colour );
+ glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_colour, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
+
+ for( int y = 0; y < world.h; y ++ )
+ {
+ for( int x = 0; x < world.w; x ++ )
+ {
+ glUniform2f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x, (float)y );
+ glUniform4f( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1.0f, 1.0f, 1.0f, 1.0f );
+ glDrawArrays( GL_TRIANGLES, 0, 6 );
+ }
+ }
}
+
+void vg_ui(void){}
\ No newline at end of file