commit d2437a686c9fb32a0f4f64cda286e4573172fc9e parent ac53ee631124de8c0ced40f02b1945c20cd25dc1 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Aug 23 12:37:56 +0200 Add an alpha channel to the immediate renderer Diffstat:
hm.cc | | | 17 | +++++++++-------- |
immediate.cc | | | 2 | +- |
immediate.h | | | 7 | +++++-- |
diff --git a/hm.cc b/hm.cc @@ -21,9 +21,9 @@ static const GLchar * const vert_src = GLSL( in vec3 position; - in vec3 colour; + in vec4 colour; - out vec3 frag_colour; + out vec4 frag_colour; void main() { gl_Position = vec4( position, 1.0 ); @@ -32,12 +32,12 @@ static const GLchar * const vert_src = GLSL( ); static const GLchar * frag_src = GLSL( - in vec3 frag_colour; + in vec4 frag_colour; out vec4 screen_colour; void main() { - screen_colour = vec4( frag_colour, 1.0 ); + screen_colour = frag_colour; } ); @@ -91,29 +91,30 @@ extern "C" GAME_INIT( game_init ) { const float crosshair_thickness = 0.005; const float crosshair_length = 0.02; + const glm::vec4 red( 1, 0, 0, 1 ); immediate_triangle( &state->test_immediate, glm::vec3( -crosshair_length, -crosshair_thickness, 0 ), glm::vec3( -crosshair_length, crosshair_thickness, 0 ), glm::vec3( crosshair_length, crosshair_thickness, 0 ), - glm::vec3( 1, 0, 0 ) + red ); immediate_triangle( &state->test_immediate, glm::vec3( crosshair_length, crosshair_thickness, 0 ), glm::vec3( crosshair_length, -crosshair_thickness, 0 ), glm::vec3( -crosshair_length, -crosshair_thickness, 0 ), - glm::vec3( 1, 0, 0 ) + red ); immediate_triangle( &state->test_immediate, glm::vec3( -crosshair_thickness / aspect, crosshair_length * aspect , 0 ), glm::vec3( crosshair_thickness / aspect, crosshair_length * aspect , 0 ), glm::vec3( crosshair_thickness / aspect, -crosshair_length * aspect , 0 ), - glm::vec3( 1, 0, 0 ) + red ); immediate_triangle( &state->test_immediate, glm::vec3( crosshair_thickness / aspect, -crosshair_length * aspect , 0 ), glm::vec3( -crosshair_thickness / aspect, -crosshair_length * aspect , 0 ), glm::vec3( -crosshair_thickness / aspect, crosshair_length * aspect , 0 ), - glm::vec3( 1, 0, 0 ) + red ); glClearColor( 0, 0.5, 0.7, 1 ); diff --git a/immediate.cc b/immediate.cc @@ -12,7 +12,7 @@ void immediate_init( ImmediateContext * const ctx, ImmediateTriangle * const mem void immediate_triangle( ImmediateContext * const ctx, const glm::vec3 v1, const glm::vec3 v2, const glm::vec3 v3, - const glm::vec3 colour + const glm::vec4 colour ) { assert( ctx->num_triangles < ctx->max_triangles - 1 ); diff --git a/immediate.h b/immediate.h @@ -5,7 +5,7 @@ struct ImmediateVertex { glm::vec3 pos; - glm::vec3 colour; + glm::vec4 colour; }; struct ImmediateTriangle { @@ -19,7 +19,10 @@ struct ImmediateContext { }; void immediate_init( ImmediateContext * const ctx, ImmediateTriangle * const memory, const size_t max_triangles ); -void immediate_triangle( ImmediateContext * const ctx, const glm::vec3 v1, const glm::vec3 v2, const glm::vec3 v3, const glm::vec3 colour ); + +void immediate_triangle( ImmediateContext * const ctx, + const glm::vec3 v1, const glm::vec3 v2, const glm::vec3 v3, const glm::vec4 colour ); + void immediate_render( ImmediateContext * const ctx, const GLuint at_position, const GLuint at_colour ); void immediate_clear( ImmediateContext * const ctx );