# depth problem

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

## Recommended Posts

I just started moving my cube arround and it will clip of parts of the object when I decrease my z cord. The farther I get back it gets clipped off. Like it I move it to 0.5f then parts of this is getting clipped. I looked over my code and couldn't find a problem. I have my depth buffers set up correctly. Anyone know something I should check that could be the problem? thanks vbuser

##### Share on other sites
Quote:
 Original post by vbuser1338I just started moving my cube arround and it will clip of parts of the object when I decrease my z cord. The farther I get back it gets clipped off. Like it I move it to 0.5f then parts of this is getting clipped. I looked over my code and couldn't find a problem. I have my depth buffers set up correctly. Anyone know something I should check that could be the problem?thanks vbuser

Increase your near and far plane sizes.

##### Share on other sites
Could I use gluPerspective to do this? And what is the first parameter mean?
Fovy . It says 'the field of view angle,in degrees,in the y-direction.' What would I put under this?
Thanks vbuser

##### Share on other sites
Quote:
 Original post by vbuser1338Could I use gluPerspective to do this? And what is the first parameter mean?Fovy . It says 'the field of view angle,in degrees,in the y-direction.' What would I put under this?Thanks vbuser

Try this call
gluPerspective(60.0, screen_width / screen_height, .005, 1000.0);

HTH???

##### Share on other sites

There is something I'm not getting here. I'm not sure where to place this thing. It ether does nothing or nothing shows up at all. All searches on the function have the exact same blurb. Defines the function prams and says a little about what its for. No examples of it being used.

My little level dosn't look very big right now. Need to get some more room.

##### Share on other sites
I got it working by putting 45 for the first parameter. Are you talking about where to place gluPerspective? I put it right after my call to gl_projection for my matrix in my Init function.
Thanks for the help
vbuser

##### Share on other sites
Quote:
 Original post by vbuser1338I got it working by putting 45 for the first parameter. Are you talking about where to place gluPerspective? I put it right after my call to gl_projection for my matrix in my Init function.Thanks for the help vbuser

Ok I may have to upgrade this "issue" to "problem." I'm still getting squat using the gluPerspective. It doesn't seem to care what I put in. Degrees, starting/ending depth, aspect all seem to affect nothing.

Most of my setup init code is just NeHe clepto code. I've compaired to to everything else I can find and I don't see what the diff is. So behold my init code.

int initGL(GLvoid)					{         	glMatrixMode(GL_PROJECTION);    glLoadIdentity();		    	gluPerspective(60.0f, SCREEN_WIDTH / SCREEN_HEIGHT,0.1f,500.0f);  	  	glMatrixMode(GL_MODELVIEW);					              // Select The Modelview Matrix	glLoadIdentity();							              // Reset The Modelview Matrix	        glEnable(GL_TEXTURE_2D);									// Enable Texture Mapping ( NEW )	glEnable(GL_BLEND);    glShadeModel(GL_SMOOTH);									// Enable Smooth Shading	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);						// Black Background	glClearDepth(1.0f);											// Depth Buffer Setup	glEnable(GL_DEPTH_TEST);									// Enables Depth Testing	glDepthFunc(GL_LEQUAL);										// The Type Of Depth Testing To Do	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);			// Really Nice Perspective Calculations	   	BuildDisLists();                                            //build long term lists		return TRUE;												// Initialization Went OK}//end InitGL[\source]

##### Share on other sites
Quote:
Original post by Goober King
Quote:
 Original post by vbuser1338I got it working by putting 45 for the first parameter. Are you talking about where to place gluPerspective? I put it right after my call to gl_projection for my matrix in my Init function.Thanks for the help vbuser

Ok I may have to upgrade this "issue" to "problem." I'm still getting squat using the gluPerspective. It doesn't seem to care what I put in. Degrees, starting/ending depth, aspect all seem to affect nothing.

Most of my setup init code is just NeHe clepto code. I've compaired to to everything else I can find and I don't see what the diff is. So behold my init code.

*** Source Snippet Removed ***

Where is your rendering code? If you are doing immediate mode you might have your windings wrong try CCW or CW rotations.

##### Share on other sites
Quote:
Original post by MARS_999
Quote:
Original post by Goober King
Quote:
 Original post by vbuser1338I got it working by putting 45 for the first parameter. Are you talking about where to place gluPerspective? I put it right after my call to gl_projection for my matrix in my Init function.Thanks for the help vbuser

Ok I may have to upgrade this "issue" to "problem." I'm still getting squat using the gluPerspective. It doesn't seem to care what I put in. Degrees, starting/ending depth, aspect all seem to affect nothing.

Most of my setup init code is just NeHe clepto code. I've compaired to to everything else I can find and I don't see what the diff is. So behold my init code.

*** Source Snippet Removed ***

Where is your rendering code? If you are doing immediate mode you might have your windings wrong try CCW or CW rotations.

Well here's some of it. What would matter anyway. Most of the rest is tied up in convenience functions. I really only need the simplest things. Strait on view with a little zooming in and out.

As I'm trying to look into it and seeing how it renders I'm forced to think I'm doing something wrong. Like the on high pics show it clipping at some odd angles.

Anyway some pics and code if it helps.
void DrawMainGame(void){  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);      glLoadIdentity();      glTranslatef(CameraX,CameraY,CameraZ); //set camera   glRotatef (CameraHorzRot, 0, 1, 0);   glRotatef (CameraVertRot, 1, 0, 0);           SetGL_Color(&SystemColor); //set overal color brightness.      switch(CurrentStage)   {    case LYCANROOM: DrawLycanRoom();break;    default: DrawLycanRoom();break;   }//end switch on stage               DisplayAnimeTable(SpriteBox,32);         if(CameraMode==DEBUG)glPrint(15,15 ,"Debug Camera" ,  0,0);           /* Draw it to the screen */    SDL_GL_SwapBuffers( );   }//end draw main game

Theres not much there. The levels are simple so they are just hardcoded. Drawn in its own function for clarity and Called within the switch statement. The DisplayAnimeTable is fairly complicated. Its basicly just a list of animations running. The only drawing it does is a set of quads put together to build a frame from sprites.

I didn't know I even had a problem until I started trying to build the first level. I figured I just needed to find out how to set the depth farther. Turns out thats a bit of an issue for whatever reason.

##### Share on other sites
Looks like your far clip plane is too close. What do I mean by this?
Opengl uses 6 planes to define the viewing volume - in the case of gluPerspective it happens to be a frustum. Four of the planes form the borders of your screen. The exact position of these planes is set by the call to gluPerspective. It is possible to set them more precisely with glFrustum - but for many applications gluPerspective is more than sufficient. The last two planes are the near and far plane - their distance from your screen is set by the last two parameters to gluPerspective. In your case they are at depths .1 and 500, which means that only objects within this depth range will be drawn. The screenshot you posted shows that the back of the metal box thing is going outside the clip volume and thus not being drawn. The solution is simply to change the 500 to some larger value like 1000 or 1500.
A word of caution. The depth buffer is scaled according to the distance between the near and far planes. Pushing the far plane out to far or pulling the near plane in too close can cause depth buffer inaccuracies especially in distant objects. The way you have things set you will have no problems - but as you start adjusting the near and far clip planes be aware that you want them as close as possible. In particular the near plane should be as far as you can tolorate - .5 is more than fine but don't pull it closer unless you have to.
I hope that this helps

##### Share on other sites
Quote:
 Original post by chowe6685Looks like your far clip plane is too close. What do I mean by this?Opengl uses 6 planes to define the viewing volume - in the case of gluPerspective it happens to be a frustum. Four of the planes form the borders of your screen. The exact position of these planes is set by the call to gluPerspective. It is possible to set them more precisely with glFrustum - but for many applications gluPerspective is more than sufficient. The last two planes are the near and far plane - their distance from your screen is set by the last two parameters to gluPerspective. In your case they are at depths .1 and 500, which means that only objects within this depth range will be drawn. The screenshot you posted shows that the back of the metal box thing is going outside the clip volume and thus not being drawn. The solution is simply to change the 500 to some larger value like 1000 or 1500.A word of caution. The depth buffer is scaled according to the distance between the near and far planes. Pushing the far plane out to far or pulling the near plane in too close can cause depth buffer inaccuracies especially in distant objects. The way you have things set you will have no problems - but as you start adjusting the near and far clip planes be aware that you want them as close as possible. In particular the near plane should be as far as you can tolorate - .5 is more than fine but don't pull it closer unless you have to.I hope that this helps

Well I've tried using 1000, 100, 50, 2000 and nothing changes. I've changed the viewing angle from 15-180 with no visible changes. 180 should have made it all very squishy. The gluPerspective function dosn't seem to be doing anything. It cannot return an error so I can't check to see if it fails. I've also tried fiddling with glFrstrm but that also didn't seem to affect anything, but in all fairness, I'm not sure how to be sure I'm using it correctly.

##### Share on other sites
Quote:
 Original post by Goober KingWell I've tried using 1000, 100, 50, 2000 and nothing changes. I've changed the viewing angle from 15-180 with no visible changes. 180 should have made it all very squishy. The gluPerspective function dosn't seem to be doing anything. It cannot return an error so I can't check to see if it fails. I've also tried fiddling with glFrstrm but that also didn't seem to affect anything, but in all fairness, I'm not sure how to be sure I'm using it correctly.

If changing those parameters didn't do anything noticeable, you are most likely resetting the projection matrix elsewhere in your program, making that call to gluPerspective()/glFrustum() meaningless. Check the rest of your code for any place where you switch to the projection matrix and make sure you aren't altering it.

##### Share on other sites
Quote:
Original post by Kalidor
Quote:
 Original post by Goober KingWell I've tried using 1000, 100, 50, 2000 and nothing changes. I've changed the viewing angle from 15-180 with no visible changes. 180 should have made it all very squishy. The gluPerspective function dosn't seem to be doing anything. It cannot return an error so I can't check to see if it fails. I've also tried fiddling with glFrstrm but that also didn't seem to affect anything, but in all fairness, I'm not sure how to be sure I'm using it correctly.

If changing those parameters didn't do anything noticeable, you are most likely resetting the projection matrix elsewhere in your program, making that call to gluPerspective()/glFrustum() meaningless. Check the rest of your code for any place where you switch to the projection matrix and make sure you aren't altering it.

Well you may be right. For whatever reason I cannot figure out, makeing the calls outside of the OpenGL init function works. Right now it sets it when it starts up the Title screen instead. I would really rather not put it there but until I figure out what is causing the problem I may be stuck. Where ever it goes its working now. That was enough to get me to a solution so koodos and all.

##### Share on other sites

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