132001f49Smrg 232001f49Smrg/* Copyright (c) Mark J. Kilgard, 1994. */ 332001f49Smrg 432001f49Smrg/** 532001f49Smrg * (c) Copyright 1993, Silicon Graphics, Inc. 632001f49Smrg * ALL RIGHTS RESERVED 732001f49Smrg * Permission to use, copy, modify, and distribute this software for 832001f49Smrg * any purpose and without fee is hereby granted, provided that the above 932001f49Smrg * copyright notice appear in all copies and that both the copyright notice 1032001f49Smrg * and this permission notice appear in supporting documentation, and that 1132001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising 1232001f49Smrg * or publicity pertaining to distribution of the software without specific, 1332001f49Smrg * written prior permission. 1432001f49Smrg * 1532001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 1632001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1732001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1832001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1932001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 2032001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 2132001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 2232001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 2332001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 2432001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 2532001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 2632001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 2732001f49Smrg * 2832001f49Smrg * US Government Users Restricted Rights 2932001f49Smrg * Use, duplication, or disclosure by the Government is subject to 3032001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 3132001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 3232001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor 3332001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement. 3432001f49Smrg * Unpublished-- rights reserved under the copyright laws of the 3532001f49Smrg * United States. Contractor/manufacturer is Silicon Graphics, 3632001f49Smrg * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 3732001f49Smrg * 3832001f49Smrg * OpenGL(TM) is a trademark of Silicon Graphics, Inc. 3932001f49Smrg */ 4032001f49Smrg/* bezsurf.c 4132001f49Smrg * This program renders a lighted, filled Bezier surface, 4232001f49Smrg * using two-dimensional evaluators. 4332001f49Smrg */ 4432001f49Smrg#include <stdlib.h> 4532001f49Smrg#include "glut_wrap.h" 4632001f49Smrg 4732001f49SmrgGLfloat ctrlpoints[4][4][3] = 4832001f49Smrg{ 4932001f49Smrg { 5032001f49Smrg {-1.5, -1.5, 4.0}, 5132001f49Smrg {-0.5, -1.5, 2.0}, 5232001f49Smrg {0.5, -1.5, -1.0}, 5332001f49Smrg {1.5, -1.5, 2.0}}, 5432001f49Smrg { 5532001f49Smrg {-1.5, -0.5, 1.0}, 5632001f49Smrg {-0.5, -0.5, 3.0}, 5732001f49Smrg {0.5, -0.5, 0.0}, 5832001f49Smrg {1.5, -0.5, -1.0}}, 5932001f49Smrg { 6032001f49Smrg {-1.5, 0.5, 4.0}, 6132001f49Smrg {-0.5, 0.5, 0.0}, 6232001f49Smrg {0.5, 0.5, 3.0}, 6332001f49Smrg {1.5, 0.5, 4.0}}, 6432001f49Smrg { 6532001f49Smrg {-1.5, 1.5, -2.0}, 6632001f49Smrg {-0.5, 1.5, -2.0}, 6732001f49Smrg {0.5, 1.5, 0.0}, 6832001f49Smrg {1.5, 1.5, -1.0}} 6932001f49Smrg}; 7032001f49Smrg 7132001f49Smrgstatic void 7232001f49Smrginitlights(void) 7332001f49Smrg{ 7432001f49Smrg GLfloat ambient[] = 7532001f49Smrg {0.2, 0.2, 0.2, 1.0}; 7632001f49Smrg GLfloat position[] = 7732001f49Smrg {0.0, 0.0, 2.0, 1.0}; 7832001f49Smrg GLfloat mat_diffuse[] = 7932001f49Smrg {0.6, 0.6, 0.6, 1.0}; 8032001f49Smrg GLfloat mat_specular[] = 8132001f49Smrg {1.0, 1.0, 1.0, 1.0}; 8232001f49Smrg GLfloat mat_shininess[] = 8332001f49Smrg {50.0}; 8432001f49Smrg 8532001f49Smrg glEnable(GL_LIGHTING); 8632001f49Smrg glEnable(GL_LIGHT0); 8732001f49Smrg 8832001f49Smrg glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 8932001f49Smrg glLightfv(GL_LIGHT0, GL_POSITION, position); 9032001f49Smrg 9132001f49Smrg glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 9232001f49Smrg glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 9332001f49Smrg glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 9432001f49Smrg} 9532001f49Smrg 9632001f49Smrgstatic void 9732001f49Smrgdisplay(void) 9832001f49Smrg{ 9932001f49Smrg glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 10032001f49Smrg glPushMatrix(); 10132001f49Smrg glRotatef(85.0, 1.0, 1.0, 1.0); 10232001f49Smrg glEvalMesh2(GL_FILL, 0, 20, 0, 20); 10332001f49Smrg glPopMatrix(); 10432001f49Smrg glFlush(); 10532001f49Smrg} 10632001f49Smrg 10732001f49Smrgstatic void 10832001f49Smrgmyinit(void) 10932001f49Smrg{ 11032001f49Smrg glClearColor(0.0, 0.0, 0.0, 1.0); 11132001f49Smrg glEnable(GL_DEPTH_TEST); 11232001f49Smrg glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 11332001f49Smrg 0, 1, 12, 4, &ctrlpoints[0][0][0]); 11432001f49Smrg glEnable(GL_MAP2_VERTEX_3); 11532001f49Smrg glEnable(GL_AUTO_NORMAL); 11632001f49Smrg glEnable(GL_NORMALIZE); 11732001f49Smrg glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); 11832001f49Smrg initlights(); /* for lighted version only */ 11932001f49Smrg} 12032001f49Smrg 12132001f49Smrgstatic void 12232001f49SmrgmyReshape(int w, int h) 12332001f49Smrg{ 12432001f49Smrg glViewport(0, 0, w, h); 12532001f49Smrg glMatrixMode(GL_PROJECTION); 12632001f49Smrg glLoadIdentity(); 12732001f49Smrg if (w <= h) 12832001f49Smrg glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w, 12932001f49Smrg 4.0 * (GLfloat) h / (GLfloat) w, -4.0, 4.0); 13032001f49Smrg else 13132001f49Smrg glOrtho(-4.0 * (GLfloat) w / (GLfloat) h, 13232001f49Smrg 4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -4.0, 4.0); 13332001f49Smrg glMatrixMode(GL_MODELVIEW); 13432001f49Smrg glLoadIdentity(); 13532001f49Smrg} 13632001f49Smrg 13732001f49Smrgstatic void 13832001f49Smrgkey(unsigned char k, int x, int y) 13932001f49Smrg{ 14032001f49Smrg switch (k) { 14132001f49Smrg case 27: /* Escape */ 14232001f49Smrg exit(0); 14332001f49Smrg break; 14432001f49Smrg default: 14532001f49Smrg return; 14632001f49Smrg } 14732001f49Smrg glutPostRedisplay(); 14832001f49Smrg} 14932001f49Smrg 15032001f49Smrgint 15132001f49Smrgmain(int argc, char **argv) 15232001f49Smrg{ 15332001f49Smrg glutInit(&argc, argv); 15432001f49Smrg glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 15532001f49Smrg glutCreateWindow(argv[0]); 15632001f49Smrg myinit(); 15732001f49Smrg glutReshapeFunc(myReshape); 15832001f49Smrg glutDisplayFunc(display); 15932001f49Smrg glutKeyboardFunc(key); 16032001f49Smrg glutMainLoop(); 16132001f49Smrg return 0; /* ANSI C requires main to return int. */ 16232001f49Smrg} 163