View Full Version : gl_FragCoord doesn't change
05-07-2010, 04:11 AM
Hi. I'm trying to combine a number of previously generated views into one and in this process I need to know the view which is currently being rendered, so to speak. The problem is that gl_FragCoord remains constant.
Does anyone have any idea about what might cause something like that? My guess is that it has something to do with the fact that I'm switching between render targets/framebuffers a lot and have missed setting something somewhere.
I'm using OpenGL 3.2 and GLSL 1.5.
(For the time being I just thought I'd see if anyone had encountered this before. The source to recreate the problem is a bit large so I'll post that if no one can think of anything.)
05-07-2010, 06:56 AM
What is your hardware/os/driver?
gl_FragCoord works for me: always has the coordinate of the current fragment for a fragment shader.
There was a problem with gl_FragCoord before, on ATI, when the driver didn't support accessing this var correctly, but it's been fixed at least for half a year from now.
05-07-2010, 07:38 AM
GeForce 8800 GT/Windows Vista/latest drivers
It works for me too most of the time. In the program I have a number of passes rendering to the same texture2DArray followed by a combination pass which is meant to combine those views into a texture2D and then finally (in the test application I'm currently working on) a pass that shows that final texture.
The variable works in the final pass but not in the rest. Each of those passes uses their own framebuffers though they render to the same texture (except the combiner).
I'll include the rendering function below in case it'll help:
void R3DRender(R3DRenderPass* render_pass)
glViewport(0, 0, render_pass->out_width, render_pass->out_height);
glDrawArrays(render_pass->render_mode, 0, render_pass->num_vertex_elements);
05-07-2010, 10:56 AM
So you claim that gl_FragCoord doesn't work on NV when rendering to a texture2DArray. I guess you are selecting a layer in GL rather than in the geometry shader? Anyway, you can post the shader code here to let us look for mistakes. If that doesn't work, try to create a test application ("out_color = gl_FragCoord", render to a layer).
05-07-2010, 11:11 AM
Yeah, I was just working on a minimal example. Hang on a bit.
So yeah, I figured out the problem and it was extremely stupid. So while I am embarrased about it I'll just write it down in case someone comes across this thread with a similar problem:
// The wrong one
// The right one
// R3DBuildShaderProgram(&passthrough_vshader, 0,
// &passthrough_fshader, &passthrough_program)
As you can see I was using the wrong variable when linking the final shader which seems to have caused all these problems (I had some weird color problems as well but didn't think they were as immediately important). Strangely the code went through the linking and it did render an image to the screen from the correct passes.
Sorry to have wasted your time but thanks for having taking an interest :|
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.