Jump to content
  • Advertisement
Sign in to follow this  
vbuser1338

depth problem

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by vbuser1338
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


Increase your near and far plane sizes.

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by vbuser1338
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


Try this call


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



HTH???

Share this post


Link to post
Share on other sites
I was about to ask the same question.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by vbuser1338
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


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 this post


Link to post
Share on other sites
Quote:
Original post by Goober King
Quote:
Original post by vbuser1338
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


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 this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
Quote:
Original post by Goober King
Quote:
Original post by vbuser1338
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


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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!