Hey, let's slow down a bit here :) Yes, that's true that you receive the matrix by glGetFloatv(GL_MODELVIEW_MATRIX, ptr)
... But that's definitely not the thing you should do here!
Let me explain:
In GLSL, built-in variables like gl_ModelViewProjectionMatrix
or functions like ftransform()
are deprecated - that's right, but that's only because the whole matrix stack is deprecated in GL 3.x and you're supposed to use your own matrix stack (or use any other solution, a matrix stack is helpful but isn't obligatory!).
If you're still using the matrix stack, then you're relying on functionality from OpenGL 2.x or 1.x. That's okay since all of this is still supported on modern graphics cards because of the GL compatibility profile - it's good to switch to a new GL version, but you can stay with this for now.
But if you are using an older version of OpenGL (with matrix stack), also use an older version of GLSL. Try 1.2, because higher versions (including your 1.5) are designed to be compatible with OpenGL3, where things such as projection or modelview matrices no longer exist in OpenGL and are expected to be passed explicitly as custom, user-defined uniform
variables if needed.
The correspondence between OpenGL and GLSL versions used to be a bit tricky (before they cleaned up the version numbering to match), but it should be more or less similar to:
GL GLSL
4.1 - 4.1
4.0 - 4.0
3.3 - 3.3
3.2 - 1.5
3.1 - 1.4
3.0 - 1.3
2.x and lower - 1.2 and lower
So, long story short - the shader builtin uniforms are deprecated because the corresponding functionality in OpenGL is also deprecated; either go for a higher version of OpenGL or a lower version of GLSL.
Best Answer
In OpenGL 3+ :
varying
is deprecatedconst
is for... well, constants !uniform
is for per draw call (at most) valuesin
is for input from the previous pipeline stage, i.e. per vertex (or per fragment) values at most, per primitive if using glAttribDivisor and hardware instanciationout
is for output to the next stageRegarding outputs for fragment shaders : in OpenGL3 and up, most of the built-in variables for fragment shader output (such as
gl_FragColor
, with the notable exception ofgl_FragDepth
) are deprecated and should be replaced with user-definedout
variables.If you are outputting to the default framebuffer, whatever you declare as the output of the fragment shader ends up in the color buffer. If you've bound an FBO with multiple color buffers (i.e. multiple render targets), you'll need to manually bind each of your
out
variables to the correct color buffer index viaglBindFragDataLocationIndexed
.All the details you could ever want about both the GLSL ('server') side and the OpenGL ('client') side can be found :