From OpenGL Reference
Jump to navigation Jump to search

Contains the window-relative coordinates of the current fragment.



Available only in the fragment language,gl_FragCoordis an input variable that contains the window relative coordinate (x, y, z, 1/w) values for the fragment. If multi-sampling, this value can be for any location within the pixel, or one of the fragment samples. This value is the result of fixed functionality that interpolates primitives after vertex processing to generate fragments. The z component is the depth value that would be used for the fragment's depth if no shader contained any writes to gl_FragDepth .

gl_FragCoordmay be redeclared with the additional layout qualifier identifiers origin_upper_left or pixel_center_integer . By default,gl_FragCoordassumes a lower-left origin for window coordinates and assumes pixel centers are located at half-pixel centers. For example, the (x, y) location (0.5, 0.5) is returned for the lower-left-most pixel in a window. The origin ofgl_FragCoordmay be changed by redeclaringgl_FragCoordwith the origin_upper_left identifier. The values returned can also be shifted by half a pixel in both x and y by pixel_center_integer so it appears the pixels are centered at whole number pixel offsets. This moves the (x, y) value returned bygl_FragCoordof (0.5, 0.5) by default to (0.0, 0.0) with pixel_center_integer .

Ifgl_FragCoordis redeclared in any fragment shader in a program, it must be redeclared in all fragment shaders in that program that have static use ofgl_FragCoord. Redeclaringgl_FragCoordwith any accepted qualifier affects onlygl_FragCoord.xandgl_FragCoord.y. It has no affect on rasterization, transformation or any other part of the OpenGL pipeline or language features.

Version Support[edit]

gl_FragCoord 1.1+

See Also[edit]



Copyright© 2011-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999.