Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

What is the range of gl_FragCoord.xy ? I know gl_FragCoord s are screen coordinates but what is the actual range? ( 0, width - 1 ) or ( 1, width ) ? And what kind of error (if any) would glsl compiler generate say I did something like gl_FragCoord.x - 5 when i do some fragcoord based calculation?

ps: I don't need normalization.

Why would you think that the compiler would generate an error if you subtracted one number from another? Nicol Bolas May 29, 2013 at 23:15

I did a test to the actual range of gl_FragCoord.xy , by using the following shader code and glReadPixels(0, 0, 1024, 1024, GL_RED, GL_FLOAT, xxx) to get the output of the shader from my framebuffer object, and the FBO had attached a texture which's internal format is GL_R32F .

out highp vec4 Output;
void main()
    Output = vec4(gl_FragCoord.xy, 0.0, 1.0);

The actual result is: gl_FragCoord.xy is in the range [0.5, 1023.5], not [0.0, 1023.0].

From the spec: "By default, gl_FragCoord assumes a lower-left origin for window coordinates and assumes pixel centers are located at half-pixel coordinates. For example, the (x, y) location (0.5, 0.5) is returned for the lower-left-most pixel in a window" Pay attention to pixel centers concept. – Ripi2 Aug 15, 2018 at 12:31 khronos.org/opengl/wiki/… There are two layout qualifiers that can affect the result. origin_upper_left and pixel_center_integer. pixel_center_integer will be shifted by a half-pixel, so that the center of each pixel is an integer value. – KAlO2 Jun 2, 2021 at 10:12 thankx, i use vec4 coord=gl_FragCoord-0.5; int index = int(coord.y * width + coord.x); – roberto Jun 23, 2021 at 10:02

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.