help me with viewing functions

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

i am totally confused with those viewing functions, such as glViewport, glLoadIdentity, glOrtho, glMatrixMode and so on. i have read the "Chapter 3: Viewing" of the red book but still don't understand, i need someone to explain these things to me, such as when to use it, where to use it...
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);     // Select The Projection Matrix
glLoadIdentity();                // Reset The Projection Matrix
// Calculate The Aspect Ratio And Set The Clipping Volume
if (h == 0) h = 1;
gluPerspective(45, (float)w/(float)h, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);      // Select The Modelview Matrix
glLoadIdentity();                // Reset The Modelview Matrix
}



Share on other sites
glViewport is used to constrain your rendering to a smaller region of the renderingcontext.
glMatrixMode sets the current matrix... If that's any use :)

What is happening is like this;

Constrain the viewport to go from (0,0) to (w,h).
Set the current matrix to GL_PROJECTION (the projection-matrix).
Reset the projection-matrix.
Set up the projection-matrix, with 45fov, aspect w/h, near clipplane to 0.1, and far to 100.0.
The set the current matrix to GL_MODELVIEW.
Reset the modelview-matrix.

Is that anywhere near detailed enough?

Share on other sites
ok, but that still didn't make it clear to me.

sorry, i still have a lot to ask:

1. when should i use glLoadIdentity()?
2. what's the current matrix?
3. does glMatrixMode() change the current matrix? and when should i use glMatrixMode()?
4. when we reset the matrix, our position go back to the origin?
5. how do i have a text on the screen keeps its position and size, so that when i move the camera or do other things, the text will not be affected?

Share on other sites
Quote:
 Original post by miica1. when should i use glLoadIdentity()?2. what's the current matrix?3. does glMatrixMode() change the current matrix? and when should i use glMatrixMode()?4. when we reset the matrix, our position go back to the origin?5. how do i have a text on the screen keeps its position and size, so that when i move the camera or do other things, the text will not be affected?

1. When you want to reset the current matrix... You wanna do this once (or more) each frame.

2. Usually it's modelview-matrix. All matix-operations (such as glRotate, glTranslate etc.) are performed on the current-matrix.

3. No it doesn't change anything, it just sets the current matrix. It's just the matrix which you want to operate on (usually modelview, as mentioned earlier).

4. Yes!

5. You could do like this:
Do Camera-transformations
Render stuff
Render text

Shoot, if you have further questions :)

Share on other sites
no, i have no further questions :) thanks for your answers, i go read some tutorials again and found that i can understand those things better now, i can handle the rest, thanks again.