Problems with transformations, culling, and understanding in general

Ok, so I want to try out a little opengl programming. So I go and start reading the OpenGL Programming Guide v1.0. I follow the instructions, and I think I understand things, but then those things don’t work! In specific, transformations don’t do what they do in everyone else’s sourcecode, stuff gets culled where I’m not expecting it, and glFrustum has no effect whatsoever! If anyone can help me, I’d be most appreciative.

Here’s some code:
glViewport(0, 0, (GLsizei) x, (GLsizei y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-100, 100, -100, 100, 0.001, 10000.0);
glMatrixMode(GL_MODELVIEW);

The above gets run once per window resize and at the start of the program. The numbers I pass to glFrustum do not affect the scene rendered at all! What am I doing wrong?

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glRotatef(cam_rot_z, 0.0, 0.0, 1.0);
glRotatef(360 - cam_rot_y, 0.0, 1.0, 0.0);
glRotatef(cam_rot_x, 1.0, 0.0, 0.0);
glTranslatef(-cam_x, -cam_y, -cam_z);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

That is supposed to set up the viewing system to point in the right direction. cam_x through cam_z are the coordinates of the viewer, and cam_rot_x through cam_rot_z are the number of degrees (I think?) around each axis that the viewer is rotated. Depending on what you read, there are a million ways to do the above, but I chose this method so I would understand it. But ofcourse it doesn’t work. The object I’m viewing rotates and moves as if all those negative signs weren’t there at all. I hope someone can help me with all this.

Phil

I had some trouble with setting up viewing aswell. You might want to see a topic called default camera on this beginner discussion board. Some other people helped me.

But I will try to give a shot a what I know.

I think one of the parenthesis were off on this line:

glViewport(0,0,(GLsizei)x, (GLsizei)y);

I assume x is the windows width and y is the windows height. I think this is the rectangle the image wil get blitted into.

I think that all the rotation and translation should be done in GL_MODELVIEW. It looks like your code has the translations and rotations in GL_PROJECTION mode.

Also note, when the view is first set up it is by default looking down the negative z axis. So, looking into the screen is looking down the negative z axis. x axis is right to left going positive. positive y axis is going from top to bottom. So, anymodel that is put at the origin is going to have to be translated -500 on z. ( into the middle of your visible area which is 0.001 to 1000 )

Thanks for the info. I made a mistake copying the glViewport() line. From everything I have read, moving the camera should be done from the GL_PROJECTION matrix, but I’m going to try doing it in GL_MODELVIEW too. I’ll also look for that topic you mentioned.

No, you definately should not use the projection matrix for “moving the camera”. Always use the modelview matrix to change the point of view. Transforming the projection matrix is likely to screw up fog calculations among other things as well.

Thanks a lot. Now, the only thing I need to figure out is why glFrustum doesn’t affect the viewing rectangle. No matter what I do, it always stays at -1, 1, -1, 1. I’m not sure about the depth parameters.

Ok, I went back and read that other thread. I think I’ve figured everything out, at least no the program works. Unfortunately, I had to resort to gluPerspective. I don’t like this because it means I need to link against glu32, and because I didn’t figure out why glFrustum wasn’t working. It seems like everyone is using glu anyways, so maybe that’s okay. Can anyone let me know the advantages and disadvantages, if there are any, of using glu?

nothing to do with glOrtho or anything is it?

-kebabinho