Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Near Clip Plane

I'm working on interactive scenes for a computer graphics course. I've set up a program which will generate color cubes, and let me rotate them with the keyboard. However they're getting cut open by the near clip plane of my camera:

Color cubes being clipped

I've tried to use gluPerspective, but the OpenGL documentation doesn't give any examples of its use. I found it being used in an example program online, and semi-replicated their code:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 65, 1, 0.01, 100 );
glMatrixMode(GL_MODELVIEW);

Any thoughts?

UPDATE: As suggested in the comments below, I tried using glFrustum instead, with the following code:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -0.5, 0.5, -0.5, 0.5, 0.1, 100 );
glMatrixMode(GL_MODELVIEW);

Again, there was no difference. Am I not pushing the resulting matrices correctly or something?

like image 225
Nick Avatar asked Nov 04 '22 13:11

Nick


1 Answers

Perhaps you need to move your objects a little farther from the Camera. Right now it seems that they are closer than 0.0.

Considering your update "I moved the cubes one whole unit away from the camera, and now as they rotate they get clipped by both the near and the far clip planes" your cubes may be too large for your clipping depth (100 - 0.1). Move cubes away from the camera by 50 and set your clipping planes to 0.1 .. 1000 to make sure everything fits.

If the problem remains we might need to look at your matrices code.

like image 146
Kromster Avatar answered Nov 11 '22 04:11

Kromster