GLSL simple question

Hello

If I understand well, in the vertex shader, the gl_Position built-in variable should get a clip-space value, that means a value between [-1,-1,-1,1] and [1,1,1,1].

So if my vertex shader is

"
#version 330 core
main()
{
gl_Position=vec4(0,0,0,1);
}
"

and my fragment shader is

"
#version 330 core

out vec4 color;

main()
{
color=vec4(1,0,0,1);
}
"

for anything drawn with “glDrawArrays(…);” juste before swapping the buffers,I should see a red point in the middle of the screen.
But it doesn’t work, someone could explain me where is the mistake?

Thanks for the help
Cathy L.

The code itself should be correct, but I just tried it in my program and also don’t see the red dot.

My assumption is that due to some odd rounding errors or the resolution, the point is considered “too small” and thus not drawn. If you try to draw some 2D faces instead, you should see a result…

Ok I’m gonna try, thanks a lot!
At least you validate what I said about gl_Position, that was my main interest.

If you are drawing something other than GL_POINTS then I don’t think you will see anything. For example a triangle with the same coordinates will not be drawn at all. Try drawing points with the above shaders and if you are already doing that maybe your depth culls them.

Good, I’ll try!
Thanks a lot

It works with GL_POINTS, thanks again!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.