132001f49Smrg/** Test Z-axis clipping of a triangle */ 232001f49Smrg 332001f49Smrg 432001f49Smrg#include <stdio.h> 532001f49Smrg#include <stdlib.h> 632001f49Smrg#include "glut_wrap.h" 732001f49Smrg 832001f49Smrg 932001f49Smrgstatic GLboolean ztest = GL_FALSE; 1032001f49Smrg 1132001f49Smrg 1232001f49Smrgstatic void 1332001f49SmrgReshape(int width, int height) 1432001f49Smrg{ 1532001f49Smrg glViewport(0, 0, width, height); 1632001f49Smrg glMatrixMode(GL_PROJECTION); 1732001f49Smrg glLoadIdentity(); 1832001f49Smrg glOrtho(-1.0, 1.0, -1.0, 1.0, 2.0, 10.0); 1932001f49Smrg glMatrixMode(GL_MODELVIEW); 2032001f49Smrg glTranslatef(0, 0, -6.0); 2132001f49Smrg} 2232001f49Smrg 2332001f49Smrg 2432001f49Smrgstatic void 2532001f49SmrgKey(unsigned char key, int x, int y) 2632001f49Smrg{ 2732001f49Smrg if (key == 'z') { 2832001f49Smrg ztest = !ztest; 2932001f49Smrg printf("ztest = %d\n", ztest); 3032001f49Smrg fflush(stdout); 3132001f49Smrg } 3232001f49Smrg else if (key == 27) { 3332001f49Smrg exit(1); 3432001f49Smrg } 3532001f49Smrg glutPostRedisplay(); 3632001f49Smrg} 3732001f49Smrg 3832001f49Smrg 3932001f49Smrgstatic void 4032001f49SmrgDraw(void) 4132001f49Smrg{ 4232001f49Smrg glClearColor(0.5, 0.5, 0.5, 1.0); 4332001f49Smrg glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 4432001f49Smrg 4532001f49Smrg if (ztest) 4632001f49Smrg glEnable(GL_DEPTH_TEST); 4732001f49Smrg else 4832001f49Smrg glDisable(GL_DEPTH_TEST); 4932001f49Smrg 5032001f49Smrg glBegin(GL_TRIANGLES); 5132001f49Smrg glColor3f(0, 0, 1); 5232001f49Smrg glVertex3f(-0.5, 0.7, -10.0); 5332001f49Smrg glColor3f(1, 0, 0); 5432001f49Smrg glVertex3f(-0.5, -0.7, -10.0); 5532001f49Smrg glColor3f(0, 1, 0); 5632001f49Smrg glVertex3f(1.0, 0.0, 12.0); 5732001f49Smrg glEnd(); 5832001f49Smrg 5932001f49Smrg glutSwapBuffers(); 6032001f49Smrg} 6132001f49Smrg 6232001f49Smrg 6332001f49Smrgint 6432001f49Smrgmain(int argc, char **argv) 6532001f49Smrg{ 6632001f49Smrg glutInit(&argc, argv); 6732001f49Smrg glutInitWindowPosition(0, 0); 6832001f49Smrg glutInitWindowSize(250, 250); 6932001f49Smrg glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 7032001f49Smrg glutCreateWindow(*argv); 7132001f49Smrg 7232001f49Smrg glutReshapeFunc(Reshape); 7332001f49Smrg glutKeyboardFunc(Key); 7432001f49Smrg glutDisplayFunc(Draw); 7532001f49Smrg glutMainLoop(); 7632001f49Smrg return 0; 7732001f49Smrg} 78