1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
6 SHADER_DEFINE( shader_tile_colour
,
9 "layout (location=0) in vec2 a_co;"
11 "uniform vec2 uOffset;"
15 "gl_Position = vec4( uPv * vec3( a_co + uOffset, 1.0 ), 1.0 );"
20 "uniform vec4 uColour;"
24 "FragColor = uColour;"
27 UNIFORMS({ "uPv", "uOffset", "uColour" })
46 } world
= { .w
= 4, .h
= 4 };
48 int main( int argc
, char *argv
[] )
50 vg_init( argc
, argv
, "FishLadder" );
53 void vg_register(void)
55 SHADER_INIT( shader_tile_colour
);
60 glGenVertexArrays( 1, &world
.tile_vao
);
61 glGenBuffers( 1, &world
.tile_vbo
);
65 0.05f
, 0.05f
, 0.05f
, 0.95f
, 0.95f
, 0.95f
,
66 0.05f
, 0.05f
, 0.95f
, 0.95f
, 0.95f
, 0.05f
69 glBindVertexArray( world
.tile_vao
);
70 glBindBuffer( GL_ARRAY_BUFFER
, world
.tile_vbo
);
79 glVertexAttribPointer( 0, 2, GL_FLOAT
, GL_FALSE
, 2 * sizeof(float), (void*)0 );
80 glEnableVertexAttribArray( 0 );
87 glDeleteVertexArrays( 1, &world
.tile_vao
);
88 glDeleteBuffers( 1, &world
.tile_vbo
);
93 float ratio
= (float)vg_window_y
/ (float)vg_window_x
;
94 float const size
= 7.5f
;
96 m3x3_projection( m_projection
, -size
, size
, size
*ratio
, -size
*ratio
);
97 m3x3_identity( m_view
);
98 m3x3_translate( m_view
, (v3f
){ -0.5f
* world
.w
, -0.5f
* world
.h
} );
99 m3x3_mul( m_projection
, m_view
, vg_pv
);
100 vg_projection_update();
105 glViewport( 0,0, vg_window_x
, vg_window_y
);
107 glDisable( GL_DEPTH_TEST
);
108 glClearColor( 0.01f
, 0.01f
, 0.01f
, 1.0f
);
109 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
111 glBindVertexArray( world
.tile_vao
);
112 SHADER_USE( shader_tile_colour
);
113 glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_colour
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
115 for( int y
= 0; y
< world
.h
; y
++ )
117 for( int x
= 0; x
< world
.w
; x
++ )
119 glUniform2f( SHADER_UNIFORM( shader_tile_colour
, "uOffset" ), (float)x
, (float)y
);
120 glUniform4f( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 1.0f
, 1.0f
, 1.0f
, 1.0f
);
121 glDrawArrays( GL_TRIANGLES
, 0, 6 );