Should I call glLoadIdentity each time I render or cumulatively add translations? Does the latter option provide any performance advantage?

// in game loop
glTranslatef(position.x, position.y, position.z);
glDrawArrays(...);

// in input handling code
if (KeyDown(LEFT))
position.x = position.x - 0.01;


// in game loop
glTranslatef(change_position.x, ...);
glDrawArrays(...);

// in input handling code
if (KeyDown(LEFT))
change_position.x = -0.01;

• That's old way of OpenGL rendering. Modelview and projection matrices have been removed since OpenGL 3. Now they are only emulated. So i would go with uniform vec3 for position. Jul 12 '12 at 17:56
• I know it's the old way, but the same principles apply if I were to use GLM. Are you saying you would go for the option with glLoadIdentity? If not, please leave an answer with code and clarify. I would happily accept it. Jul 12 '12 at 18:11

In the old days of OpenGL with the builtin matrix stacks, glLoadIdentity served as a simple way of setting the topmost matrix on the stack to the identity matrix.

If you were doing a transform like T1*R1*S1*T2*R2*S2, it has the benefit of letting you use the same cumulative form for each of the operations instead of having to overload the first one to be able to replace the existing state instead of multiply with it.

That is, you have:

glLoadIdentity();
glTranslatef(..); glRotatef(); glScalef();
glTranslatef(..); glRotatef(); glScalef();


glClearAndTranslatef(..); glRotatef(); glScalef();

You can compare this to addition or multiplication of scalars - you can always add in the identity element for the operation: 1 * a * b and 0 + c + d.