I’m trying to create a program such that my shader receives a position in world space and draws an impostor at that position.
The geometry shader is supposed to take the single vertex position and create a quad, and the fragment shader then textures the quad.
The shaders work (in theory), because I can see the result in my shader builder (XCode’s OpenGL Shader Builder). Of course, when I load them into my program, nothing shows.
I’m pretty sure it’s due to the information being received (or not) from the main program. May someone take a look and tell me what I should or shouldn’t have order to get it to work, please?
I’ve posted relevant code below…
<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;”>
uniform vec4 position;
void main()
{
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewMatrix * position;
}
[/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;”>
uniform sampler2D tex;
void main()
{
vec4 color = texture2D(tex, gl_TexCoord[0].xy);
float x = color.x;
float y = color.y;
float zz = (x + y) / 2.0;
if (zz <= 0.2)
discard;
gl_FragColor = gl_Color * color;
}
[/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
uniform float size;
void main()
{
gl_TexCoord[0] = gl_TexCoordIn[0][0];
gl_FrontColor = gl_FrontColorIn[0];
// Vertex 1
gl_TexCoord[0].st = vec2(0.0,1.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(-size, -size);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();
// Vertex 2
gl_TexCoord[0].st = vec2(0.0,0.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(-size, size);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();
// Vertex 3
gl_TexCoord[0].st = vec2(1.0,1.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(size, -size);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();
// Vertex 4
gl_TexCoord[0].st = vec2(1.0,0.0);
gl_Position = gl_PositionIn[0];
gl_Position.xy += vec2(size, size);
gl_Position = gl_ProjectionMatrix * gl_Position;
EmitVertex();
EndPrimitive();
}
[/QUOTE]</div>
<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;”>
// Geometry shader info in create shader program function
…
glProgramParameteriEXT(p, GL_GEOMETRY_INPUT_TYPE_EXT, GL_POINTS);
glProgramParameteriEXT(p, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP);
glProgramParameteriEXT(p, GL_GEOMETRY_VERTICES_OUT_EXT, 4);
…
// Impostor function
void impostor(){
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, impostortexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUseProgram(p);
glUniform1i(glGetUniformLocation(p, "tex"), 0);
glUniform1i(glGetUniformLocation(p, "size"), 2);
glUniform3fv(glGetUniformLocation(p, "position"), 1, origin);
// start - what do I put here?
glBegin(GL_POINTS);
glVertex3fv(origin);
glEnd();
// stop - what do I put here?
glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
}
[/QUOTE]</div>