commit b2e8ce37fc53f72154c1ab42c59d20c54267147c parent ed9bb5b63711e2fe74449c41c3884d7fb40aed7d Author: Michael Savage <mikejsavage@gmail.com> Date: Sat Jul 22 13:38:52 +0300 Better wireframe mode Diffstat:
renderer.cc | | | 3 | +++ |
shaders.cc | | | 2 | ++ |
shaders.h | | | 1 | + |
shaders/wireframe.glsl | | | 22 | ++++++++++++++++++++++ |
diff --git a/renderer.cc b/renderer.cc @@ -730,9 +730,12 @@ static void set_render_state( const RenderState & state ) { if( state.wireframe != previous_render_state.wireframe ) { if( state.wireframe ) { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + glEnable( GL_POLYGON_OFFSET_LINE ); + glPolygonOffset( -1, -1 ); } else { glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + glDisable( GL_POLYGON_OFFSET_LINE ); } } diff --git a/shaders.cc b/shaders.cc @@ -54,6 +54,8 @@ void shaders_init() { shaders[ SHADER_SHADOWED_VERTEX_COLOURS ].path = "shaders/shadowed_vertex_colours.glsl"; shaders[ SHADER_SHADOWED_VERTEX_COLOURS ].texture_uniform_names[ 0 ] = "shadowmap"; + shaders[ SHADER_WIREFRAME ].path = "shaders/wireframe.glsl"; + int failed = hotload_shaders(); if( failed != 0 ) { FATAL( "failed to load shaders" ); diff --git a/shaders.h b/shaders.h @@ -13,6 +13,7 @@ enum ShaderID { SHADER_WRITE_SHADOW_MAP, SHADER_DEBUG_RENDER_SHADOW_MAP, SHADER_SHADOWED_VERTEX_COLOURS, + SHADER_WIREFRAME, SHADER_COUNT, }; diff --git a/shaders/wireframe.glsl b/shaders/wireframe.glsl @@ -0,0 +1,22 @@ +#ifdef VERTEX_SHADER + +in vec3 position; + +layout( std140 ) uniform view { + mat4 V; + mat4 P; +}; + +void main() { + gl_Position = P * V * vec4( position, 1.0 ); +} + +#else + +out vec4 screen_colour; + +void main() { + screen_colour = vec4( 1.0, 1.0, 1.0, 1.0 ); +} + +#endif