bezmesh.c revision 32001f49
1 2/* Copyright (c) Mark J. Kilgard, 1994. */ 3 4/** 5 * (c) Copyright 1993, Silicon Graphics, Inc. 6 * ALL RIGHTS RESERVED 7 * Permission to use, copy, modify, and distribute this software for 8 * any purpose and without fee is hereby granted, provided that the above 9 * copyright notice appear in all copies and that both the copyright notice 10 * and this permission notice appear in supporting documentation, and that 11 * the name of Silicon Graphics, Inc. not be used in advertising 12 * or publicity pertaining to distribution of the software without specific, 13 * written prior permission. 14 * 15 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 16 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 18 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 19 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 20 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 21 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 22 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 23 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 24 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 25 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 26 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 27 * 28 * US Government Users Restricted Rights 29 * Use, duplication, or disclosure by the Government is subject to 30 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 31 * (c)(1)(ii) of the Rights in Technical Data and Computer Software 32 * clause at DFARS 252.227-7013 and/or in similar or successor 33 * clauses in the FAR or the DOD or NASA FAR Supplement. 34 * Unpublished-- rights reserved under the copyright laws of the 35 * United States. Contractor/manufacturer is Silicon Graphics, 36 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 37 * 38 * OpenGL(TM) is a trademark of Silicon Graphics, Inc. 39 */ 40/* bezsurf.c 41 * This program renders a lighted, filled Bezier surface, 42 * using two-dimensional evaluators. 43 */ 44#include <stdlib.h> 45#include "glut_wrap.h" 46 47GLfloat ctrlpoints[4][4][3] = 48{ 49 { 50 {-1.5, -1.5, 4.0}, 51 {-0.5, -1.5, 2.0}, 52 {0.5, -1.5, -1.0}, 53 {1.5, -1.5, 2.0}}, 54 { 55 {-1.5, -0.5, 1.0}, 56 {-0.5, -0.5, 3.0}, 57 {0.5, -0.5, 0.0}, 58 {1.5, -0.5, -1.0}}, 59 { 60 {-1.5, 0.5, 4.0}, 61 {-0.5, 0.5, 0.0}, 62 {0.5, 0.5, 3.0}, 63 {1.5, 0.5, 4.0}}, 64 { 65 {-1.5, 1.5, -2.0}, 66 {-0.5, 1.5, -2.0}, 67 {0.5, 1.5, 0.0}, 68 {1.5, 1.5, -1.0}} 69}; 70 71static void 72initlights(void) 73{ 74 GLfloat ambient[] = 75 {0.2, 0.2, 0.2, 1.0}; 76 GLfloat position[] = 77 {0.0, 0.0, 2.0, 1.0}; 78 GLfloat mat_diffuse[] = 79 {0.6, 0.6, 0.6, 1.0}; 80 GLfloat mat_specular[] = 81 {1.0, 1.0, 1.0, 1.0}; 82 GLfloat mat_shininess[] = 83 {50.0}; 84 85 glEnable(GL_LIGHTING); 86 glEnable(GL_LIGHT0); 87 88 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 89 glLightfv(GL_LIGHT0, GL_POSITION, position); 90 91 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 92 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 93 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 94} 95 96static void 97display(void) 98{ 99 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 100 glPushMatrix(); 101 glRotatef(85.0, 1.0, 1.0, 1.0); 102 glEvalMesh2(GL_FILL, 0, 20, 0, 20); 103 glPopMatrix(); 104 glFlush(); 105} 106 107static void 108myinit(void) 109{ 110 glClearColor(0.0, 0.0, 0.0, 1.0); 111 glEnable(GL_DEPTH_TEST); 112 glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 113 0, 1, 12, 4, &ctrlpoints[0][0][0]); 114 glEnable(GL_MAP2_VERTEX_3); 115 glEnable(GL_AUTO_NORMAL); 116 glEnable(GL_NORMALIZE); 117 glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); 118 initlights(); /* for lighted version only */ 119} 120 121static void 122myReshape(int w, int h) 123{ 124 glViewport(0, 0, w, h); 125 glMatrixMode(GL_PROJECTION); 126 glLoadIdentity(); 127 if (w <= h) 128 glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w, 129 4.0 * (GLfloat) h / (GLfloat) w, -4.0, 4.0); 130 else 131 glOrtho(-4.0 * (GLfloat) w / (GLfloat) h, 132 4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -4.0, 4.0); 133 glMatrixMode(GL_MODELVIEW); 134 glLoadIdentity(); 135} 136 137static void 138key(unsigned char k, int x, int y) 139{ 140 switch (k) { 141 case 27: /* Escape */ 142 exit(0); 143 break; 144 default: 145 return; 146 } 147 glutPostRedisplay(); 148} 149 150int 151main(int argc, char **argv) 152{ 153 glutInit(&argc, argv); 154 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 155 glutCreateWindow(argv[0]); 156 myinit(); 157 glutReshapeFunc(myReshape); 158 glutDisplayFunc(display); 159 glutKeyboardFunc(key); 160 glutMainLoop(); 161 return 0; /* ANSI C requires main to return int. */ 162} 163