pouët.net

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 :)
added on the 2011-03-17 15:18:14 by texel texel
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.
added on the 2011-03-17 15:33:28 by psonice psonice
psonice, that doesn't work (I've tried), because gl_FragCoord are screen space and seems not to be vertex position dependant
added on the 2011-03-17 15:37:50 by texel texel
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.
added on the 2011-03-17 15:45:08 by xernobyl xernobyl
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
added on the 2011-03-17 15:53:59 by xernobyl xernobyl
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.
added on the 2011-03-17 15:59:01 by psonice psonice
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
added on the 2011-03-17 16:43:43 by hornet hornet
If this is for something with a size limit, "720-" in your shader is going to be smaller than another API function import/call.
added on the 2011-03-17 16:45:18 by ferris ferris
...and it will also save you space still using gl_FragCoord, since you don't need a vertex shader in that case.
added on the 2011-03-17 16:48:58 by ferris ferris
Quote:
don't use gl_FragCoord

hornet: why not? it's perfect for post processing screen passes.
added on the 2011-03-17 16:59:54 by xernobyl xernobyl
Is it not possible to just work with the standard coords btw?
added on the 2011-03-17 17:18:54 by psonice psonice

login