I’m just trying to get a program to work using a simple geometry shader and a vbo.
The output i am getting is as if the program is ignoring the geometry shader.
I’m including all the relevant code where the error might occur.
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (Vertex Shader) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
attribute vec4 vertex;
void main()
{
gl_Position = gl_ModelViewMatrix * vertex;
}
[/QUOTE]</div>
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (Geometry Shader) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
#extension GL_EXT_geometry_shader4 : enable
void main()
{
gl_Position = gl_PositionIn[0];
gl_Position.y += 2.0;
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();
EndPrimitive();
}
[/QUOTE]</div>
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (Fragment Shader) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
void main()
{
gl_FragColor = vec4(0.0,0.0,1.0,1.0);
}
[/QUOTE]</div>
The shader files could not be simpler.
Here is the relevant code in the main file.
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (Relevant main code) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
GLuint vert_attr = 0;
…
void renderBuffer(GLuint vbo)
{
if (!pUSE) {
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_POINTS, 0, 3);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
else {
glUseProgram(ptest);
vert_attr = glGetAttribLocation(ptest, “vertex”);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableVertexAttribArray(vert_attr);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(vert_attr, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawArrays(GL_POINTS, 0, 3);
glDisableVertexAttribArray(vert_attr);
glUseProgram(0);
}
}
…
GLuint setShader3(char *vert, char *frag, char *geom)
{
char *vs = NULL, *fs = NULL, *gs = NULL;
v = glCreateShader(GL_VERTEX_SHADER);
f = glCreateShader(GL_FRAGMENT_SHADER);
g = glCreateShader(GL_GEOMETRY_SHADER_EXT);
vs = textFileRead(vert);
fs = textFileRead(frag);
gs = textFileRead(geom);
const char * vv = vs; const char * ff = fs; const char * gg = gs;
glShaderSource(v, 1, &vv,NULL);
glShaderSource(f, 1, &ff,NULL);
glShaderSource(g, 1, &gg,NULL);
free(vs); free(fs); free(gs);
glCompileShader(v); glCompileShader(f); glCompileShader(g);
printShaderInfoLog(v);
printShaderInfoLog(f);
printShaderInfoLog(g);
GLuint p = glCreateProgram();
glAttachShader(p,v);
glAttachShader(p,f);
glAttachShader(p,g);
glProgramParameteriEXT(p,GL_GEOMETRY_INPUT_TYPE_EXT,GL_POINTS);
glProgramParameteriEXT(p,GL_GEOMETRY_OUTPUT_TYPE_EXT,GL_POINTS);
glProgramParameteriEXT(p,GL_GEOMETRY_VERTICES_OUT_EXT,4);
glLinkProgram(p);
printProgramInfoLog(p);
return p;
}
[/QUOTE]</div>
In the display function, glColor is set to red. So toggling the boolean pUSE will enable/disable using the shader program which re-colors the vertices in blue and (is supposed to) translate each point.
When the shader program is enabled the 3 points are re-colored correctly but no translation is taking place and no matter how much i increase the value in the geometry shader file, the points stay put.
What am I doing wrong here?
NB = I am using an old version for OpenGL (2.x) and GLSL (1.2) because I have to be able to run the program on a campus computer that doesn’t have the new lovely versions.