PDA

View Full Version : GLSL simple question



zedrummer
02-18-2014, 12:49 AM
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.

Brokenmind
02-18-2014, 02:02 AM
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...

zedrummer
02-18-2014, 03:17 AM
Ok I'm gonna try, thanks a lot!
At least you validate what I said about gl_Position, that was my main interest.

Godlike
02-18-2014, 03:42 AM
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.

zedrummer
02-18-2014, 12:33 PM
Good, I'll try!
Thanks a lot

zedrummer
02-19-2014, 12:09 AM
It works with GL_POINTS, thanks again!