gluLookat(), gluPerspective(), near and far plane distances

Started by
3 comments, last by d_rappo 22 years, 2 months ago
Hi, This question is in a similar vein to Lee J K''s post on screen depth. Basically I just cannot seem to get gluLookat() to work for me. When I run my app I get a spinning cube at the centre of the screen, but everything disappears when I resize the window. My code to handle the WM_SIZE message in the WndProc is as follows: ... glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90, width / height, 1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ... then in my Reder() function gluLookAt(camera[0], camera[1], camera[2], // camera location 0.0, 0.0, -30.0, // looking at 0.0, 1.0, 0.0); // up vector ... SwapBuffers(); Initially, camera[0], camera[1], and camera[2] are set to zero. I also have code that is supposed to zoom the camera in and out by decrementing the value of camera[2] to zoom in, and incrementing camera[2] to zoom out. Since my near plane has a distance of one and the far plane a distance of 100 I would definitely expect to see something but all I get is a big blank. Can anybody help me? What am I doing wrong? Thanks
Advertisement
Personally I do very little in callbacks, besides set some variables. In the Reshape, I simply store the requested window size.

Then in my main display func, I use these values to setup my window/viewport etc. Every run of display completely sets up the frame from scratch. Considering all the rendering going on, there is virtually no overhead in doing this.

And personally I don''t use glulookat like that, I do the reverse-camera thing.

zin

zintel.com - 3d graphics & more or less
zintel.com - 3d graphics & more or less
Personally, I cannot see anything wrong with your code. I have some code which is very similar. Here is my resize function, as you can see, their are very few differences.


glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,650.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

I would recommend increasing your view depth to a slightly larger number or changing the first parameter to 54.0f like mine to see if it works. Other than that I can only think that the problem is elsewhere in the program.

Sorry I couldn''t help much
- Weasalmongler
Not being an openGL expert yet, but getting there, one of the things that I have learned about OGL is that initialisation is very important as is modularity. A big clue to the blank screen thing is that have you put the very important code:

glClear(GL_DEPTH_BUFFER_BIT, GL_COLOR_BUFFER_BIT);
glLoadIdentity();

I have found that the rest of my code is fine when the above is placed correctly, normally near the start of any OpenGL operations.

On the other hand, it could be that you are not handling you WM_PAINT message appropriately, or style as CS_VREDRAW and/or CS_HREDRAW, which ensure that the window is completely redrawn on resizing.

Hope this helps.



Regards,
Mathematix.
Your problem is probably the integer divide in the calculation of the aspect ratio. I had a similar problem...my screen was black when height was greater than width(since AR=0 then), and every other time it was distorted(AR=1).

Finally, make sure that your geometry is between the near & far plane( like at around -30 z)

This topic is closed to new replies.

Advertisement