medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 754961cb7e2707b3156b2f37789c5ae626fe99f5
parent 41941b065f9e30d78b263335842258b616e45eaf
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Fri Jun 17 23:51:24 +0100

Better skybox effort

Diffstat:
skybox.cc | 29++++++++++++++---------------
skybox.h | 2+-
2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/skybox.cc b/skybox.cc @@ -20,24 +20,23 @@ static const GLchar * const vert_src = GLSL( in vec3 position; - out vec3 direction; + out vec3 pos; - uniform mat4 VP; + uniform mat4 V; void main() { - vec4 world_pos = VP * vec4( position, 1.0 ); - gl_Position = world_pos.xyww; - direction = position; + // gl_Position = vec4( ( V * vec4( position, 1.0 ) ).xy, 1.0, 1.0 ); + gl_Position = vec4( position.xy, 1.0, 1.0 ); + pos = gl_Position.xyz; } ); static const GLchar * frag_src = GLSL( - in vec3 direction; - + in vec3 pos; out vec4 screen_colour; void main() { - screen_colour = vec4( 1.0, 0.0, 0.0, 1.0 ); + screen_colour = vec4( pos, 1.0 ); } ); @@ -57,7 +56,7 @@ static GLuint cube_indices[] = { 7, 6, 3, 2, 0, 6, 4, 7, 5, 3, 1, 0, 5, 4 }; void skybox_init( Skybox * skybox ) { skybox->shader = compile_shader( vert_src, frag_src, "screen_colour" ); skybox->at_position = glGetAttribLocation( skybox->shader, "position" ); - skybox->un_vp = glGetUniformLocation( skybox->shader, "vp" ); + skybox->un_v = glGetUniformLocation( skybox->shader, "v" ); glGenVertexArrays( 1, &skybox->vao ); glBindVertexArray( skybox->vao ); @@ -83,9 +82,12 @@ void skybox_render( const Skybox * skybox, const glm::vec3 & angles ) { glm::vec4 x = P * glm::vec4( cube_verts[ i ], 1.0f ); printf( "%d: %.3f %.3f %.3f %.3f\n", i, x.x, x.y, x.z, x.w ); } - glm::mat4 vp = glm::rotate( + glUseProgram( skybox->shader ); + glBindVertexArray( skybox->vao ); + + const glm::mat4 V = glm::rotate( glm::rotate( - P, + glm::mat4(), angles.x, glm::vec3( 1, 0, 0 ) ), @@ -93,10 +95,7 @@ void skybox_render( const Skybox * skybox, const glm::vec3 & angles ) { glm::vec3( 0, 0, 1 ) ); - glUseProgram( skybox->shader ); - glBindVertexArray( skybox->vao ); - - glUniformMatrix4fv( skybox->un_vp, 1, GL_FALSE, glm::value_ptr( vp ) ); + glUniformMatrix4fv( skybox->un_v, 1, GL_FALSE, glm::value_ptr( V ) ); glDrawElements( GL_TRIANGLE_STRIP, array_count( cube_indices ), GL_UNSIGNED_INT, 0 ); diff --git a/skybox.h b/skybox.h @@ -7,7 +7,7 @@ struct Skybox { GLuint shader; GLuint at_position; - GLuint un_vp; + GLuint un_v; GLuint vao; GLuint vbo;