//#define VG_STEAM
#include "vg/vg.h"
+SHADER_DEFINE( shader_tile_colour,
+
+ // VERTEX
+ "layout (location=0) in vec2 a_co;"
+ "uniform mat3 uPv;"
+ "uniform vec2 uOffset;"
+ ""
+ "void main()"
+ "{"
+ "gl_Position = vec4( uPv * vec3( a_co + uOffset, 1.0 ), 1.0 );"
+ "}",
+
+ // FRAGMENT
+ "out vec4 FragColor;"
+ "uniform vec4 uColour;"
+ ""
+ "void main()"
+ "{"
+ "FragColor = uColour;"
+ "}"
+ ,
+ UNIFORMS({ "uPv", "uOffset", "uColour" })
+)
+
m3x3f m_projection;
m3x3f m_view;
m3x3f m_mdl;
*data;
u32 w, h;
-};
+
+ GLuint tile_vao;
+ GLuint tile_vbo;
+} world = { .w = 1, .h = 1 };
int main( int argc, char *argv[] )
{
vg_init( argc, argv, "FishLadder" );
}
-void vg_register(void){}
-void vg_start(void){}
-void vg_free(void){}
+void vg_register(void)
+{
+ 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.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f
+ };
+
+ 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_free(void)
+{
+ glDeleteVertexArrays( 1, &world.tile_vao );
+ glDeleteBuffers( 1, &world.tile_vbo );
+}
+
+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_mul( m_projection, m_view, vg_pv );
+ vg_projection_update();
+}
void vg_render(void)
{
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