Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an array in my vertex shader like this:

uniform mat4 MeshTransforms[20];

At the moment I'm just updating the entire array of matrices like so:

int meshTransforms = ARBShaderObjects.glGetUniformLocationARB(shader, "MeshTransforms");
ARBShaderObjects.glUniformMatrix4ARB(meshTransforms, false, UnitTransformMatrices);

Where UnitTransformMatrices is a float buffer containing the transform matrices of some units.

I'd like to just update a single matrix in the array (just update one unit transform matrix). So how can I overwrite a single matrix in the middle of the matrix array?

This is using the LWJGL, so I'm limited to the functionality it provides.

share|improve this question
Can't you use the put method? UnitTransformMatrices.put(at, num) – Luis Estrada Mar 16 '12 at 13:27
Thanks Luis, but that would only update the copy sitting in RAM, not what's on the video card's memory. – Byte56 Mar 16 '12 at 14:20
Please stop using the ARBShaderObjects extension. GLSL has been core OpenGL for 8+ years now; just use the core feature. – Nicol Bolas Mar 16 '12 at 17:18
Thanks Nicol, do you know how to do that in LWJGL and would that help me with the question I have? – Byte56 Mar 16 '12 at 20:54
Shaders became standard in GL 2.0, so you should find the appropriate functions in the GL20 class. And no, it doesn't have anything to do with your problem specifically, but you still shouldn't use the old extensions. – Nicol Bolas Mar 17 '12 at 5:21
up vote 2 down vote accepted

From glGetUniformLocation. In the description section, the element operator '[]' may be used to select elements within arrays. So you would grab the location

GLuint location = glGetUniformLocation( vertexShader , "variable[element]" );

Then from glUniform.

glvoid glUniformMatrix4fv( location , count , bool Transpose ,  const GLfloat *value);

Location is from above, count is the number of elements you plan on changing( sequentially from "location") and the rest you know.

I am not aware of the limitations you have in place with LWJGL, but am only hoping to set you on the right track to show you what's possible so you can check out your own documentation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.