132001f49Smrg/* 232001f49Smrg * Copyright (c) 1993-1997, Silicon Graphics, Inc. 332001f49Smrg * ALL RIGHTS RESERVED 432001f49Smrg * Permission to use, copy, modify, and distribute this software for 532001f49Smrg * any purpose and without fee is hereby granted, provided that the above 632001f49Smrg * copyright notice appear in all copies and that both the copyright notice 732001f49Smrg * and this permission notice appear in supporting documentation, and that 832001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising 932001f49Smrg * or publicity pertaining to distribution of the software without specific, 1032001f49Smrg * written prior permission. 1132001f49Smrg * 1232001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 1332001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1432001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1532001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1632001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 1732001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 1832001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 1932001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 2032001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 2132001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 2232001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 2332001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 2432001f49Smrg * 2532001f49Smrg * US Government Users Restricted Rights 2632001f49Smrg * Use, duplication, or disclosure by the Government is subject to 2732001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 2832001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 2932001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor 3032001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement. 3132001f49Smrg * Unpublished-- rights reserved under the copyright laws of the 3232001f49Smrg * United States. Contractor/manufacturer is Silicon Graphics, 3332001f49Smrg * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 3432001f49Smrg * 3532001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 3632001f49Smrg */ 3732001f49Smrg 3832001f49Smrg#include "glut_wrap.h" 3932001f49Smrg#include <stdlib.h> 4032001f49Smrg#include <stdio.h> 4132001f49Smrg 4232001f49Smrgstatic int leftFirst = GL_TRUE; 4332001f49Smrg 4432001f49Smrgstatic struct { GLenum func; const char *str; } funcs[] = 4532001f49Smrg { 4632001f49Smrg { GL_LESS, "GL_LESS" }, 4732001f49Smrg { GL_LEQUAL, "GL_LEQUAL" }, 4832001f49Smrg { GL_GREATER, "GL_GREATER" }, 4932001f49Smrg { GL_GEQUAL, "GL_GEQUAL" }, 5032001f49Smrg { GL_EQUAL, "GL_EQUAL" }, 5132001f49Smrg { GL_NOTEQUAL, "GL_NOTEQUAL" }, 5232001f49Smrg { GL_ALWAYS, "GL_ALWAYS" }, 5332001f49Smrg { GL_NEVER, "GL_NEVER" }, 5432001f49Smrg }; 5532001f49Smrg 5632001f49Smrg#define NUM_FUNCS (sizeof(funcs) / sizeof(funcs[0])) 5732001f49Smrg 5832001f49Smrgstatic int curFunc = 0; 5932001f49Smrgstatic double clearVal = 1.0; 6032001f49Smrgstatic float minZ = 0.0; 6132001f49Smrgstatic float maxZ = 1.0; 6232001f49Smrg 6332001f49Smrgstatic void usage(void) 6432001f49Smrg{ 6532001f49Smrg printf("t - toggle rendering order of triangles\n"); 6632001f49Smrg printf("c - toggle Z clear value between 0, 1\n"); 6732001f49Smrg printf("f - cycle through depth test functions\n"); 6832001f49Smrg printf("n/N - decrease/increase depthrange minZ\n"); 6932001f49Smrg printf("x/X - decrease/increase depthrange maxZ\n"); 7032001f49Smrg printf("spc - reset\n"); 7132001f49Smrg printf("z - set to reverse-direction (ztrick) mode\n"); 7232001f49Smrg fflush(stdout); 7332001f49Smrg} 7432001f49Smrg 7532001f49Smrg 7632001f49Smrgstatic void init(void) 7732001f49Smrg{ 7832001f49Smrg glEnable(GL_DEPTH_TEST); 7932001f49Smrg glClearColor (1.0, 0.0, 0.0, 0.0); 8032001f49Smrg} 8132001f49Smrg 8232001f49Smrgstatic void drawLeftTriangle(void) 8332001f49Smrg{ 8432001f49Smrg /* draw yellow triangle on LHS of screen */ 8532001f49Smrg glBegin (GL_TRIANGLES); 8632001f49Smrg glColor4f(1.0, 1.0, 0.0, 0.75); 8732001f49Smrg glVertex3f(0.1, 0.9, -1.0); 8832001f49Smrg glVertex3f(0.1, 0.1, -1.0); 8932001f49Smrg glVertex3f(0.8, 0.5, 1.0); 9032001f49Smrg glEnd(); 9132001f49Smrg} 9232001f49Smrg 9332001f49Smrgstatic void drawRightTriangle(void) 9432001f49Smrg{ 9532001f49Smrg /* draw cyan triangle on RHS of screen */ 9632001f49Smrg glBegin (GL_TRIANGLES); 9732001f49Smrg glColor4f(0.0, 1.0, 1.0, 0.75); 9832001f49Smrg glVertex3f(0.9, 0.9, 0.0); 9932001f49Smrg glVertex3f(0.2, 0.5, 0.0); 10032001f49Smrg glVertex3f(0.9, 0.1, 0.0); 10132001f49Smrg glEnd(); 10232001f49Smrg} 10332001f49Smrg 10432001f49Smrgstatic void display(void) 10532001f49Smrg{ 10632001f49Smrg printf("GL_CLEAR_DEPTH = %.2f, GL_DEPTH_FUNC = %s, DepthRange(%.1f, %.1f)\n", 10732001f49Smrg clearVal, funcs[curFunc].str, minZ, maxZ); 10832001f49Smrg fflush(stdout); 10932001f49Smrg glClearDepth(clearVal); 11032001f49Smrg glDepthRange(minZ, maxZ); 11132001f49Smrg glDepthFunc(funcs[curFunc].func); 11232001f49Smrg 11332001f49Smrg glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 11432001f49Smrg 11532001f49Smrg if (leftFirst) { 11632001f49Smrg drawLeftTriangle(); 11732001f49Smrg drawRightTriangle(); 11832001f49Smrg } 11932001f49Smrg else { 12032001f49Smrg drawRightTriangle(); 12132001f49Smrg drawLeftTriangle(); 12232001f49Smrg } 12332001f49Smrg 12432001f49Smrg glFlush(); 12532001f49Smrg} 12632001f49Smrg 12732001f49Smrgstatic void reshape(int w, int h) 12832001f49Smrg{ 12932001f49Smrg glViewport(0, 0, (GLsizei) w, (GLsizei) h); 13032001f49Smrg glMatrixMode(GL_PROJECTION); 13132001f49Smrg glLoadIdentity(); 13232001f49Smrg if (w <= h) 13332001f49Smrg gluOrtho2D (0.0, 1.0, 0.0, 1.0*(GLfloat)h/(GLfloat)w); 13432001f49Smrg else 13532001f49Smrg gluOrtho2D (0.0, 1.0*(GLfloat)w/(GLfloat)h, 0.0, 1.0); 13632001f49Smrg} 13732001f49Smrg 13832001f49Smrg/* ARGSUSED1 */ 13932001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 14032001f49Smrg{ 14132001f49Smrg switch (key) { 14232001f49Smrg case 'n': 14332001f49Smrg minZ -= .1; 14432001f49Smrg break; 14532001f49Smrg case 'N': 14632001f49Smrg minZ += .1; 14732001f49Smrg break; 14832001f49Smrg case 'x': 14932001f49Smrg maxZ -= .1; 15032001f49Smrg break; 15132001f49Smrg case 'X': 15232001f49Smrg maxZ += .1; 15332001f49Smrg break; 15432001f49Smrg case 'c': 15532001f49Smrg case 'C': 15632001f49Smrg clearVal = 1.0 - clearVal; 15732001f49Smrg break; 15832001f49Smrg case 'f': 15932001f49Smrg case 'F': 16032001f49Smrg curFunc = (curFunc + 1) % NUM_FUNCS; 16132001f49Smrg break; 16232001f49Smrg case 't': 16332001f49Smrg case 'T': 16432001f49Smrg leftFirst = !leftFirst; 16532001f49Smrg break; 16632001f49Smrg case ' ': 16732001f49Smrg curFunc = 0; 16832001f49Smrg clearVal = 1.0; 16932001f49Smrg minZ = 0.0; 17032001f49Smrg maxZ = 1.0; 17132001f49Smrg break; 17232001f49Smrg case 'z': 17332001f49Smrg curFunc = 2; 17432001f49Smrg clearVal = 0.0; 17532001f49Smrg minZ = 1.0; 17632001f49Smrg maxZ = 0.0; 17732001f49Smrg break; 17832001f49Smrg case 27: /* Escape key */ 17932001f49Smrg exit(0); 18032001f49Smrg break; 18132001f49Smrg default: 18232001f49Smrg return; 18332001f49Smrg } 18432001f49Smrg glutPostRedisplay(); 18532001f49Smrg} 18632001f49Smrg 18732001f49Smrg/* Main Loop 18832001f49Smrg * Open window with initial window size, title bar, 18932001f49Smrg * RGBA display mode, and handle input events. 19032001f49Smrg */ 19132001f49Smrgint main(int argc, char** argv) 19232001f49Smrg{ 19332001f49Smrg glutInit(&argc, argv); 19432001f49Smrg glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 19532001f49Smrg glutInitWindowSize (200, 200); 19632001f49Smrg glutCreateWindow (argv[0]); 19732001f49Smrg glutReshapeFunc (reshape); 19832001f49Smrg glutKeyboardFunc (keyboard); 19932001f49Smrg glutDisplayFunc (display); 20032001f49Smrg init(); 20132001f49Smrg usage(); 20232001f49Smrg glutMainLoop(); 20332001f49Smrg return 0; 20432001f49Smrg} 205