Doubt in transformations

Hello,

I have a doubt in Model View and Projection transformation


  
initfunction()
{
   .......
}
    
reshapefunction()
{
   glViewport(x1,y1,x2,y2);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glPerspective(angle,ratio,near,far);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glLookAt(some_data);
}

display()
{
   glLoadIdentity()
   glTranslatef(some_data);
   VertexData();
} 



In the above code I understand that the function glLoadIdentity() will reset the current matrix to identity.

In function display() we have set the currentmatrix to Identity and we are the object to some position defined by glTranslatef.

In function reshape we are composing the scene by setting the viewport and giving the projection matrix and setting the camera position

My Doubt is where and how will the transformation from object space ->world space->eye cordinates.

My understanding is that in display function the object is still in object cordinates,where does it transform to eye cordinates.

-swetha

OpenGL legacy fixed function API maintains the last values for both modelview and projection matrix. When you issue a draw call, it can combine these. But there is no separate model and view matrices, so you need to always provide them combined in modelview. This is where there appears to be issue in your code: reshapefunction() looks like it sets view transformation, but all that is lost since display calls glLoadIdentity(). To fix this, remove glLookAt() from reshapefunction and instead place it after glLoadIdentity() in display().

Also consider skipping the legacy fixed function and start straight with modern OpenGL API.

GL maintains stacks of modelview and projection matrix, not just the last one. The top of the stack is only used in current operation.

gluLookAt has no effect in your code since the next glLoadIdentity resets modelview matrix.

glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glLookAt(some_data); // has no impact since the next command resets MV matrix
   glLoadIdentity(); // resets all previous MODELVIEW transform.
   glTranslatef(some_data);

Take a look at Chapter 3 from the Red Book.

Hello,

thankyou for the answer.I have changed gluLookat function to display.I understand that the transformations in display function affects MODELVIEWmatrix stack.

I want to know when will gluPerspective will take effect.
Will the matrices in PROJECTION matrix stack will be mutiplied after the display function?

-swetha

Projection matrix is multiplied with model-view matrix before transforming vertices in a vertex shader. That is all you need to know.
If you change projection matrix in the middle of your display function, that would affect all vertices drawn after that change.

Thankyou.Understood.
-swetha