开发者

GLSL with fragment shader renders only black GL_POINTS

开发者 https://www.devze.com 2022-12-22 03:00 出处:网络
I am trying to add some shaders to my old OpenGL program that draws a lot of GL_POINTS and some GL_LINES.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消