PDA

View Full Version : graphics problem



t3jem
06-10-2005, 12:35 PM
Hi I have a program with a cabin that does not look how it should. The triangles on the side of the roof are being chopped off for some reason. Here is a screen shot. http://free.hostdepartment.com/P/ProgrammingHQ/problem.JPG

I didn't have this problem until I started to swap from ortho to perspective for a health bar.

any ideas?

Ehsan Kamrani
06-10-2005, 12:59 PM
Well. It seems that the problem refers to the new and far planes of the function gluPerspective().
USe from the following function as an example:
gluPerspective( 54.0f, (GLfloat)width/(GLfloat)height, 0.1, 1000 );

Maybe the far plane in your program has been set to a small value.
-Ehsan-

t3jem
06-10-2005, 01:48 PM
No, my far value is set at 50 and my near value at 0.1. My entire area is only 10X10. It didn't have this effect until I started using the ortho view.

bansheeogl
06-10-2005, 02:42 PM
hmm is this thread new? the screenie looks like from 1992 - anyway might be a z-fighting problem

also why using ortho view?

Ehsan Kamrani
06-10-2005, 03:00 PM
Originally posted by Terminatore3:

I didn't have this problem until I started to swap from ortho to perspective for a health bar.
Now i understand...
1.Draw your home with the perspective view. Draw your health bar with the orthographic view.
2.When you want to change the definitions of the projection matrix, you should use from the function glLoadIdentity().

So you can use from the following code:
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective();

glMatrixMode( GL_MODELVIEW );
glLoadIdentity(); //optional
<Do your transformations and draw your home, your trees>
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho();

glMatrixMode( GL_MODELVIEW );
glLoadIdentity(); //optional
<Do your transformations and draw the health bar>

-Ehsan-

t3jem
06-10-2005, 03:07 PM
hmm is this thread new? the screenie looks like from 1992 No I took that screen shot today.

Anyways, Ehsan Kamrani, I think I am doing it right here is my code.


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, 1000/700, 0.001, 50);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(view.x,view.y, view.z, view.lx, view.ly, view.lz, 0, 0, 1);
<draw scene>

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5,5,-5,5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
<draw health>

Ehsan Kamrani
06-10-2005, 03:13 PM
OK. it seems that your problem refers to the znear plane in the function gluPerspective(). 0.001 is too small and is near to 0. never set the znear plane to very small values. 0.1 is suitable.
hope this helps.
-Ehsan-

t3jem
06-10-2005, 03:26 PM
great thanks!

Ehsan Kamrani
06-10-2005, 04:05 PM
You're welcome!I'm so happy that could help you.
-Ehsan-