So the function:

glLoadIdentity();

resets the matrix, so for instance we do this:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

how exactly does this work, it seems that we set the matrix and then just return it to the way it used to be.

I am not an expert, as I only recently started learning opengl myself, but from my understanding glLoadIdentity() clears the currently selected matrix. If you read through the OpenGL Documentation thoroughly, you will find that OpenGL stores four matrices of data. I learnt about them from a very helpful tutorial here. Basically the first matrix is the model matrix, it stores the offsets for the creation of stuff in your scene. The second matrix is the view matrix, it stores the offsets for the camera that views your scene. The third matrix is the modelview matrix, which is a combination of the two. The final matrix is the projection matrix, which stores information about how the camera draws the scene. Calling glLoadIdentity() resets the currently loaded matrix to an empty array (of zeroes if I remember correctly) allowing you to transform the matrices without just adding onto the previous transformations.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.