View Full Version : where has built-in variable "gl_FragColor" gone in OpenGL 4.4?

06-08-2014, 07:06 AM
The book "Interactive Computer Graphics, A Top Down Approach with Shader Based OpenGL, 6th Edition" shows a minimum snippet of fragment shader in page 86 as follows:


But another book "OpenGL Programming Guide, the official guide to learning OpenGL, version 4.3" says in page 675 that in modern version of OpenGL (at least 4.3), the following are all built-in variables we have in a fragment shader:


I can not find any variable named "gl_FragColor" appearing in the list. So, does the second book miss anything, or the first book is out-of-date (although it's the latest version of the book)? If the latter is true, i.e., the "gl_FragColor" is obsolete, what is the new name of the variable corresponding to "gl_FragColor" in OpenGL version 4.4 that can set the pixel color to red using the code similar to that in the first image? Thank you.

carsten neumann
06-08-2014, 08:15 AM
Since a fragment shader can have multiple outputs gl_FragColor at first was replaced by gl_FragData[i] where i was sent to the i-th enabled draw buffer and these days fragment shader outputs are simply declared as "out" variables, see also wiki (http://www.opengl.org/wiki/Fragment_Shader).

06-08-2014, 08:27 AM
gl_FragColor is deprecated in GLSL 1.3 (OpenGL 3.0), so about 6 years ago. :)

P.S. Interestingly, "Interactive Computer Graphics, A Top Down Approach with Shader Based OpenGL, 6th Edition" was released in 2011, and was written against OpenGL 3.1. The code on the pg.86 is probably remainder of some previous revision of the book. Nope, there is another at page 92, and 246, 293, 296, 380, 396, etc. So, the error is more serious than I thought.