GLSL Type Qualifiers
I just started reading up on GLSL but I haven't been able to find any information on using "in" and "out" qualifiers. The examples I've seen all use "attribute" "varying" and "uniform". From what I understand, using "in" and "out" replaces the need to use any of the other special type qualifiers but, I'm probably confused and wrong.
So can someone please point out the correct, most up-to-date way to use type qualifiers in GLSL? Thanks.
No you're pretty much right.
Attribute, Varying, Uniform used to be the definitions, but in newer versions of glsl they were just replaced by "in" and "out".
Vertex Shader:
"uniform" becomes "in"
"attribute" becomes "in"
"varying" becomes "out"
Fragment Shader:
"uniform" becomes "in"
"varying" becomes "in"
Attribute, Varying, Uniform used to be the definitions, but in newer versions of glsl they were just replaced by "in" and "out".
Vertex Shader:
"uniform" becomes "in"
"attribute" becomes "in"
"varying" becomes "out"
Fragment Shader:
"uniform" becomes "in"
"varying" becomes "in"
Alright cool, thanks for clarifying. I've got another small question. I noticed there's some variables that seem to get/set values directly by interacting with OpenGL automatically, is this correct?
gl_ProjectionMatrix
gl_Position
gl_FragColor
The values I assign to gl_Position and gl_FragColor will be sent to OpenGL as the final vertex position and the final fragment color automatically. Is this right? If this is true, how can I tell the Shader what my projection matrix is?
gl_ProjectionMatrix
gl_Position
gl_FragColor
The values I assign to gl_Position and gl_FragColor will be sent to OpenGL as the final vertex position and the final fragment color automatically. Is this right? If this is true, how can I tell the Shader what my projection matrix is?
Quote:Original post by X Abstract XYes, but only for older versions of OpenGL (or the compatibility profile). Newer versions of OpenGL have removed all implicit attributes and uniforms, so you have to setup all of this functionality yourself.
The values I assign to gl_Position and gl_FragColor will be sent to OpenGL as the final vertex position and the final fragment color automatically. Is this right?
Quote:If this is true, how can I tell the Shader what my projection matrix is?
glMatrixMode(GL_PROJECTION);glLoadMatrix(matrix);
Quote:Original post by swiftcoderQuote:Original post by X Abstract XYes, but only for older versions of OpenGL (or the compatibility profile). Newer versions of OpenGL have removed all implicit attributes and uniforms, so you have to setup all of this functionality yourself.
The values I assign to gl_Position and gl_FragColor will be sent to OpenGL as the final vertex position and the final fragment color automatically. Is this right?Quote:If this is true, how can I tell the Shader what my projection matrix is?*** Source Snippet Removed ***
Ok thanks but I was under the impression that glMatrixMode() was deprecated. Is it?
Quote:Original post by swiftcoderJust out of curiosity (currently I'm still using OpenGL 2.0, my graphics card sucks...), do you have an example at hand that shows how to do that? I've been getting rid of most of the fixed function stuff in my code lately and I was wondering how this would be done...
Yes, but only for older versions of OpenGL (or the compatibility profile). Newer versions of OpenGL have removed all implicit attributes and uniforms, so you have to setup all of this functionality yourself.
Quote:Ok thanks but I was under the impression that glMatrixMode() was deprecated. Is it?
Yes it is depreciated.
For core profile you have to send matrices yourself to the shader via 4x4 uniforms.
Quote:Original post by karwostsQuote:Ok thanks but I was under the impression that glMatrixMode() was deprecated. Is it?
Yes it is depreciated.
For core profile you have to send matrices yourself to the shader via 4x4 uniforms.
Thanks. This is a rediculous question but, how do you send data to a shader? I understand how to send vertex data from a VBO but not matrices like that.
Edit: Oh I guess you use glUniformMatrix4fv()
[Edited by - X Abstract X on April 11, 2010 8:11:13 PM]
Quote:Original post by kloffyRetrieve the attribute binding point by name from the shader with glGetAttribLocation(), enable the relevant attribute array with glEnableVertexAttribArray(), and provide the data with glVertexAttribPointer().
Just out of curiosity (currently I'm still using OpenGL 2.0, my graphics card sucks...), do you have an example at hand that shows how to do that? I've been getting rid of most of the fixed function stuff in my code lately and I was wondering how this would be done...
Under 3.0 or greater you need to use VBO to store your attribute arrays, but for 2.0 or 3.0 compatability profile, you can continue to use vertex array, or even fixed function with glVertexAttrib*().
See here for more details.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement