I am dealing with geometry shaders using GL_ARB_geometry_shader4 extension.

My code goes like :

GLfloat vertices[] =





glEnableVertexAttribArray (0);

glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, vertices);


My vertex shader is :

#version 150

in vec3 Position;

void main()
    gl_Position = vec4(Position,1.0);


Geometry shader is :

#version 150
#extension GL_EXT_geometry_shader4 : enable

in vec4 pos[3];

void main()
   int i;
   vec4 vertex;

    gl_Position = pos[0];

    gl_Position = pos[1];

    gl_Position = pos[2];

    gl_Position = pos[0] + vec4(0.3,0.0,0.0,0.0);


Nothing is rendered with this code. What exactly should be the mode in glDrawArrays() ? How does the GL_GEOMETRY_OUTPUT_TYPE_EXT parameter will affect glDrawArrays() ?

What I expect is 3 vertices will be passed on to Geometry Shader and using those we construct a primitive of size 4 (assuming GL_TRIANGLE_STRIP requires 4 vertices). Can somebody please throw some light on this ?

  • 3
    \$\begingroup\$ You tagged this post openGL ES but openGL ES does not support geometry shaders. \$\endgroup\$ – Thelvyn Dec 19 '12 at 12:37
  • 1
    \$\begingroup\$ @Thelvyn: My bad. Wont happen next time. \$\endgroup\$ – maverick9888 Dec 20 '12 at 8:16
  • \$\begingroup\$ Is there a reason you're using the old EXT extension instead of the GL 3.2 core functionality? I mean, you're already using GLSL 1.50; geometry shaders are a core feature for you. And they don't work like that. \$\endgroup\$ – Nicol Bolas Jan 8 '13 at 12:55

Your vec4 pos[3] variable in your geometry shader doesn't appear to be getting set, unless you didn't post the code for that. If it's being initialized to zero and never set, that could be why nothing shows up. If you want the geometry shader to get the positions output from the vertex shader, you need to use the built-in variable gl_PositionIn[] for that.

The input to glDrawArrays and similar must match the input primitive type of the geometry shader. Since you've written a geometry shader that works on triangles, you can use a triangle list, strip or fan in glDrawArrays. Each triangle generated by the draw call is sent to the geometry shader and processed separately, after being vertex-shaded.

So the way you have it now, you're drawing a triangle strip of 4 vertices, which creates 2 triangles; each of these is then passed to the geometry shader, which turns it into a strip of 2 triangles. So you end up with 4 triangles drawn altogether.

  • \$\begingroup\$ Thanks ,that was pretty useful. Somehow vertex shader wasn't happy with vec3 Position . When I changed it to vec4 Position , it worked fine. \$\endgroup\$ – maverick9888 Dec 20 '12 at 8:19
  • \$\begingroup\$ If this solved your problem, mark the answer as correct. \$\endgroup\$ – Jari Komppa Jan 8 '13 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.