PDA

View Full Version : Variable Problems about different version



apapaxionga
03-13-2011, 08:51 AM
i come from China;my English is not very good;i hope you can understand my meaning;

Does the build-in variable gl_NormalMatrix,gl_Normal in version 120 retrive the appropriate values automatically from the system automatically?;
The variable gl_NormalMatrix,gl_Normal had been deprecated in version 140,so i declare the variables

uniform mat3 NormalMatrix;
in vec3 MCNormal;

by myself;

But do i have to initialize these variables by myself,also the variables like that:
in vec4 MCVertex;
in vec3 MCNormal;
uniform mat4 MVPMatrix;

Every time when i initialize the program ,Do i have to initialize a lot of variables before i start begin program?;
Are there variables that can be initialized automatically just like gl_NormalMatrix,gl_Normal in version120?

Dark Photon
03-13-2011, 12:43 PM
Does the build-in variable gl_NormalMatrix,gl_Normal in version 120 retrive the appropriate values automatically from the system automatically?
It's probably better to say that these identifiers are "pre-associated" (that is already associated, or already bound) to specific OpenGL state. You don't have to do anything to create this association. It already exists.

In the case of gl_NormalMatrix, it is already associated with the inverse transpose of the matrix at the top of the GL_MODELVIEW matrix stack. In the case of gl_Normal, it is already associated with the current vertex normal you provide via glNormalPointer, glNormal, etc.

You still have to provide OpenGL with appropriate values for that OpenGL state. But after having done so, those values are automatically associated with those identifiers in your shader.


[when instead using user-defined uniforms/attributes:] do i have to initialize these variables by myself,
As before, you still have to provide values for these inputs. But also, because you're not populating OpenGL built-in state but instead your own user-defined state, you also have to tell OpenGL the association between your values and the identifiers in the shader.

In the case of your normal vertex attribute, there are several ways to do this. One being glBindAttribLocation:

http://www.opengl.org/wiki/GlVertexAttribPointer

which lets you associate a particular generic vertex attribute number with a "name" in the shader. With your normal matrix uniform, you do that by querying the handle for the appropriate shading language uniform, and passing that handle to the appropriate glUniform* set function:

http://www.opengl.org/wiki/GLSL_Uniform