The OpenGL function `glLoadIdentity();` is used to reset the current model-view matrix (or any other active matrix) to the identity matrix .
`glLoadIdentity();` – Set the identity matrix
1. How it works:
2. What is an identity matrix?
3. When is `glLoadIdentity();` used?
4. Example: `glLoadIdentity();` in practice
5. What happens without `glLoadIdentity();`?
6. Summary:
1.) How it works:
- A matrix in OpenGL stores transformations such as translation, rotation, and scaling .
- Each time `glLoadIdentity();` is called, the currently active matrix is reset to an identity matrix . - This deletes
all previously applied transformations , creating a neutral starting point.
2.) What is an identity matrix?
The 4×4 identity matrix that OpenGL uses looks like this:
(Image-1) Matrix4x4 |
![]() |

- All diagonal elements are 1 , all other entries are 0 .
- When a point or vector coordinate is multiplied by this matrix, it remains unchanged .
3.) When is `glLoadIdentity();` used?
- Before new transformations , to ensure they are not affected by previous ones.
- After setting the camera view , to obtain a fresh starting point for model transformations.
4.) Example: `glLoadIdentity();` in practice
void renderScene () { glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; // Clear screen glLoadIdentity () ; // Set matrix to identity matrix // Set camera position (translation backwards) glTranslatef ( 0. 0f, 0. 0f, - 5. 0f ) ; // Draw a cube drawCube () ; glutSwapBuffers () ; // Swap double buffers }
5.) What happens without `glLoadIdentity();`?
Without `glLoadIdentity();`, each new transformation would add to the previous transformation , which could lead to unexpected results.
For example, if a scene performed a translation
every frame iteration , the object would continue to move instead of staying in a fixed position.
6.) Summary:
✅ `glLoadIdentity();` resets the current matrix to the identity matrix .
✅ It is often called after `glClear()` and before new transformations.
✅ Without `glLoadIdentity();`, transformations can accumulate , producing unwanted effects.
Modern versions of OpenGL often use custom matrices and shaders instead of `glLoadIdentity();` .