View Full Version : OpenGL clipping problem

04-25-2002, 04:00 PM
Hi everyone,

I recently started exploring OpenGL on Linux (RH 7.2) and am having a clipping problem. It seems like no matter what I do, everything I put on the screen is clipped before z=1.0 and after z=-1.0 and I can't change it. Can someone give me pointers here? (I can send source code if necessary, but I'll hold off for now to save space.)


04-26-2002, 06:46 AM
I think it is best to post a small but complete program showing exactly what you are doing. Post it here or in the beginners forum if it is not linux specific.

04-26-2002, 11:14 AM
Ok...here's some simplified source code.(It draws a grid of lines. Notice the clipping on the front and back of the surface.

I'm not sure if this is Linux specific, but after comparing with some other platform code, I feel it might be.

Also, I've tried things like gluOrtho and tried a bunch of other random stuff, and ju
st can't figure out what I need to adjusting the clipping bounds.

/************************ clippingprob.c **
#include <GL/gl.h>
#include <GL/glut.h>

void display(void);
void Line(GLfloat, GLfloat, GLfloat, GLfloat);

int main(int argc, char** argv)
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ;
glutInitWindowSize (500, 500) ;
glutInitWindowPosition (100, 100) ;
glutCreateWindow ("OpenGL Display Window") ;

glClearColor(0.0, 0.0, 0.0, 0.0) ;
glutDisplayFunc (display) ;

glutMainLoop () ;

return 0 ;

void display(void)
int idx;

glRotatef(80.0, 1.5f, 0.7f, 0.0f);

//Draw a 20x20 line grid from (-1.0,-1.0,0.0) through (1.0,1.0,0.0);
for(idx = 0; idx <= 20; idx++)
Line(1.0f, (-1.0f) + (GLfloat)idx / 10.0f,
-1.0f, (-1.0f) + (GLfloat)idx / 10.0f);
for(idx = 0; idx <= 20; idx++)
Line((-1.0f) + (GLfloat)idx / 10.0f, -1.0f,
(-1.0f) + (GLfloat)idx / 10.0f, 1.0f);


void Line(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) {

/********************* EOF *****************/

compilation: gcc clippingprob.c -lGL -lGLU -lglut -lm -o clippingprob


04-28-2002, 02:29 PM
The red book says about gluOrtho2D:
"For the special case of projecting a two-dimensional image onto a two-dimensional screen, use the Utility
Library routine gluOrtho2D(). This routine is identical to the three-dimensional version, glOrtho(),
except that all the z coordinates for objects in the scene are assumed to lie between -1.0 and 1.0. If you're
drawing two-dimensional objects using the two-dimensional vertex commands, all the z coordinates are
zero; thus, none of the objects are clipped because of their z values."

If you do not have the red book can you download it from the online books section here http://gamedev.net/reference/list.asp?categoryid=31

You can use glOrtho but probably is gluPerspective or glFrustum the functions you want to use.