To create a shader program that utilizes the geometry shader to produce a wireframe on top of a shaded surface, use the following steps:
- Use the following code for the vertex shader:
layout (location = 0 ) in vec3 VertexPosition; layout (location = 1 ) in vec3 VertexNormal; out vec3 VNormal; out vec3 VPosition; uniform mat4 ModelViewMatrix; uniform mat3 NormalMatrix; uniform mat4 ProjectionMatrix; uniform mat4 MVP; void main() { VNormal = normalize( NormalMatrix * VertexNormal); VPosition = vec3(ModelViewMatrix * vec4(VertexPosition,1.0)); gl_Position = MVP * vec4(VertexPosition,1.0); }
- Use the following code for the geometry shader:
layout( triangles ) in; layout( triangle_strip, max_vertices = 3 ) out; out vec3 GNormal; ...