perspective

I have a program where my camera roams around a forest that is 20X20 units. My problem is that I can’t get the perspective right. My trees are 0.2 units wide.

Here is the code that causes the problem.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(120,4/4,0,1);
gluLookAt(view.x,view.y, view.z+0.5, view.lx, view.ly, view.lz, 0, 0, 1);
glOrtho(-1,1,-1,1,0,20);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Originally posted by Terminatore3:
[b]
{code]
gluPerspective(120,4/4,0,1);

[/b]
A znear of 0 is invalid and will kill your zbuffer, it must be a value greater then zero, try 0.1 instead.

A FOV of 120° is kind of extrem, I usually go for 45-60 depending on the situation.

Two more issues:

  1. You have to use gluPerspective OR glOrtho, not both of them.

  2. On the projection matrix you should have ONLY the projection, not the camera transformation.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (float)width/(float)height, 0.1, 50);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(...);

width and height are the dimensions of your window. The near plane should be set a bit away from the origin, never set it to 0. The far plane has to be far enough to see something, I think in your case 50 should be enough. You can play around with these values…

great!

thanks