I am trying to add some shaders to my old OpenGL program that draws a lot of GL_POINTS and some GL_LINES.
I created these two shaders:
Vertex shader:
void main()
{
vec4 v = vec4(gl_Vertex);
v.z = v.z + sin(v.x*v.x + v.y*v.y)/10.0;
gl_Position = gl_ModelViewProjectionMatrix * v;
}
Fragment shader:
#version 120
void main()
{
vec4 myOutputColor = gl_Color;
gl_FragColor = myOutputColor;
//gl_FragColor.r = 0.5;
}
These two shaders compile and link without problems. And the vertex shader works great, I can see the GL_POINTS displaced using that sin in the vertex shader. But the problem is I can only see my GL_POINTS and GL_LINES if the background color is not black because all points and lines are rendered black. It seems that all the colors set with glColor3f in the rendering code are ignored. If I uncomment the commented line in my fragment shader I can make all lines and points red, but shouldn't gl_Color correspond to the color that was set with glColor3f for each point?
Is there anything else in my OpenGL code that could cause this behaviour?
you need to pass the color through in the vertex shader.
gl_FrontColor = gl_Color;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With