PDA

View Full Version : Frustum clipping problems



Agricultures
08-09-2008, 06:03 PM
Hi There

OpenGL seems to be clipping my models at near plane 1.0, far plane 100.0 no matter what I set them as in gluPerspective.

The strange thing is is that if I disable depth testing it works fine (uses the values I set it as).
If not, my models are clipped at 1,100.

I'm not that fluent in openGL, but I've searched long and hard for solutions and similar problems to no avail. Figured I must be overlooking something simple.

Are there any GL states that would default clip planes to these values or in any other way effect clipping like this?

I'm using SDL, but don't use the SDL bindings for openGL calls if that's relevant.

Here's my openGL init code ( pretty much from NeHe ):
//---------------------------------------------------------------

glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);


//----- Configure Viewport and projection matrix
glViewport (0, 0, (GLsizei)(win_width), (GLsizei)(win_height));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45.0f, (GLdouble)win_width / (GLdouble)(win_height), nearPlane, farPlane);


And Here's the start of my drawScene function:
//---------------------------------------------------------------

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPolygonMode(GL_FRONT, GL_FILL);
glColor3f(0.9f, 0.9f, 0.9f);

glTranslated( 0.0, 0.0, zoom);
glRotated(yrot, 0.0f, 1.0f, 0.0f);
glRotated(xrot, AltXAxis[0], AltXAxis[1], AltXAxis[2]);

//----- Primitive Drawing Follows


Strait After my drawGLScene I call:
//---------------------------------------------------------------
TwDraw(); //Ant Tweak Bar Gui lib draw command
SDL_GL_SwapBuffers();


The issue being: Whatever I set my near and far planes as, my models get clipped at 1.0 and 100.0
UNLESS I call glDisable(GL_DEPTH_TEST); right before drawing primitives (then clipping is done at my specified values).

Any Ideas?

Thanks in anticipation

Agricultures
08-19-2008, 09:45 PM
Solved. It was my background that was apparently clipping my models not openGL.