UniformsGL 2.0

glUniform1f

Sets a float uniform.

Part of the family glUniform*

Signature

void glUniform1f(GLint location, GLfloat v0);

How it works

Sets one float — typical uses are time for animations, a shininess exponent, or a mix factor.

Parameters

locationGLint

Uniform location from glGetUniformLocation. -1 is silently ignored.

v0GLfloat

The value.

Tips & pitfalls

  • Uniforms are written to the program currently selected with glUseProgram.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GL_INVALID_OPERATION
No program in use, or the function's type/size does not match the uniform declared in GLSL.

Example

example.cpp
1glUniform1f(uTime, (float)glfwGetTime());
Official Khronos documentation