Links

Content Skeleton

This Page

Previous topic

shader

Next topic

OpenGL Using Cross platform(Linux/OSX) approach with GLFW, GLEW

OpenGL Geometry Shader

New API

Describes the new Geometry Shader (that are not yet available to me)

Since OpenGL 3.2 there is a third optional type of shader that sits between the vertex and fragment shaders, known as the geometry shader.

Issue with changing shader

Swapping out a geometry shader works, swapping in does not

  1. Mesa (OpenGL in software) implementation of geometry shader might be illuminating

Older API

  • http://www.opengl.org/wiki/Geometry_Shader_Examples
  • removed from core OpenGL 3.1 and above (they are only deprecated in OpenGL 3.0).
  • It is recommended that you not use this functionality in your programs.
    • BUT: THIS IS ONLY WAY TO USE GEOMETRY SHADERS CURRENTLY
//GEOMETRY SHADER
 #version 120
 #extension GL_ARB_geometry_shader4 : enable
 ///////////////////////
 void main()
 {
   //increment variable
   int i;
   vec4 vertex;
   /////////////////////////////////////////////////////////////
   //This example has two parts
   //   step a) draw the primitive pushed down the pipeline
   //            there are gl_VerticesIn # of vertices
   //            put the vertex value into gl_Position
   //            use EmitVertex => 'create' a new vertex
   //           use EndPrimitive to signal that you are done creating a primitive!
   //   step b) create a new piece of geometry
   //           I just do the same loop, but I negate the vertex.z
   //   result => the primitive is now mirrored.
   //
   // Pass-thru!
   //
   for(i = 0; i < gl_VerticesIn; i++)
   {
     gl_Position = gl_PositionIn[i];
     EmitVertex();
   }
   EndPrimitive();

   // New piece of geometry!
   for(i = 0; i < gl_VerticesIn; i++)
   {
     vertex = gl_PositionIn[i];
     vertex.z = -vertex.z;
     gl_Position = vertex;
     EmitVertex();
   }
   EndPrimitive();
 }