openGL /GLSL question
category: code [glöplog]
I'm trying to code a fragment shader, rendering with 2 triangles (like the thing Iq does).
I need to use screen space I'm using gl_FragCoord.
My question is, how to reverse the gl_FragCoord.y value? I want the 0 to be in the top of the render area instead of in the bottom. I know I could just do a subtraction of the height-1 minus the fragment coordinate, but I would like to know if there is any other way to do it with openGL, that doesn't force me to do this inside the shader.
Maybe this is obvious, but my knowledge of openGL is so little (I started yestarday to learn) so any help would be very appreciated.
Thanks in advance :)
I need to use screen space I'm using gl_FragCoord.
My question is, how to reverse the gl_FragCoord.y value? I want the 0 to be in the top of the render area instead of in the bottom. I know I could just do a subtraction of the height-1 minus the fragment coordinate, but I would like to know if there is any other way to do it with openGL, that doesn't force me to do this inside the shader.
Maybe this is obvious, but my knowledge of openGL is so little (I started yestarday to learn) so any help would be very appreciated.
Thanks in advance :)
If you're rendering 2 triangles, I guess you're setting up the texture coords somewhere. Change the sign on the y values :)
Other option, in the vertex shader: gl_Position.y = -gl_Position.y.
Other option, in the vertex shader: gl_Position.y = -gl_Position.y.
psonice, that doesn't work (I've tried), because gl_FragCoord are screen space and seems not to be vertex position dependant
There is a texture parameter that lets you set where the texture begins.
http://www.opengl.org/sdk/docs/man3/ glViewport has the equations used to convert screen to normalized. that can probably help, and glTexParameter has the equations for texture mapping. You can check that. I thought there was a function to change the texture origin (bottom left vs top left) but I couldn't find it.
Hope that helps.
http://www.opengl.org/sdk/docs/man3/ glViewport has the equations used to convert screen to normalized. that can probably help, and glTexParameter has the equations for texture mapping. You can check that. I thought there was a function to change the texture origin (bottom left vs top left) but I couldn't find it.
Hope that helps.
gl_FragCoord goes from (0,0) to (height-1, width-1), if tou want to reverse it just use do width-1 - gl_FragCoord.y
0,0 is on the bottom left
0,0 is on the bottom left
Sorry, totally misread that as texCoord! I've not seen anything to change the coordinate system, although it does ring a vague bell so maybe it's possible.
texel - don't use gl_FragCoord, and pass in the values you want in vertex-data, like psonice said. Don't start changing opengl-state... you'll regret it later :p
If this is for something with a size limit, "720-" in your shader is going to be smaller than another API function import/call.
...and it will also save you space still using gl_FragCoord, since you don't need a vertex shader in that case.
Quote:
don't use gl_FragCoord
hornet: why not? it's perfect for post processing screen passes.
Is it not possible to just work with the standard coords btw?