多通道:
#include <GL/glut.h>
void scene()
{
glColor3ub( 255, 0, 0 );
glBegin( GL_QUADS );
glVertex2i( -1, -1 );
glVertex2i( 1, -1 );
glVertex2i( 1, 1 );
glVertex2i( -1, 1 );
glEnd();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
double w = glutGet( GLUT_WINDOW_WIDTH );
double h = glutGet( GLUT_WINDOW_HEIGHT );
double ar = w / h;
glOrtho( -2 * ar, 2 * ar, -2, 2, -1, 1);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glEnable( GL_CLIP_PLANE0 );
// -y plane
GLdouble plane0[] = { -1, 0, 0, 0 };
glClipPlane( GL_CLIP_PLANE0, plane0 );
scene();
// -x plane
GLdouble plane1[] = { 0, -1, 0, 0 };
glClipPlane( GL_CLIP_PLANE0, plane1 );
scene();
glutSwapBuffers();
}
int main( int argc, char **argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
glutInitWindowSize( 640, 480 );
glutCreateWindow( "Clipping" );
glutDisplayFunc( display );
glutMainLoop();
return 0;
}