Example/Uniform Location Query Old

From OpenGL Wiki
< Example
Revision as of 05:01, 3 May 2015 by Alfonse (talk | contribs) (Example code for uniform location use, old-style.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Querying and using uniform locations, under the old introspection API.

Vertex shader code:

uniform vec3 someVector;
uniform mat4 someMatrix;
//Code must use these uniforms to be active.

C++ code:

GLuint program = //Compile and link program.
GLint someVectorLoc = glGetUniformLocation(program, "someVector");
assert(someVectorLoc != -1); //If fails, then the uniform is inactive.
GLint someMatrixLoc = glGetUniformLocation(program, "someMatrix");
assert(someMatrixLoc != -1); //If fails, then the uniform is inactive.
glUniform3f(someVectorLoc, 3.0f, 3.0f, 4.0f);
GLfloat matrix[16];
//Fill `matrix` with data. Non-transposed matrix data.
glUniformMatrix4fv(someMatrixLoc, 1, GL_FALSE, matrix);