1 /* aux2glut conversion Copyright (c) Mark J. Kilgard, 1994, 1995 */
4 * (c) Copyright 1993, Silicon Graphics, Inc.
6 * Permission to use, copy, modify, and distribute this software for
7 * any purpose and without fee is hereby granted, provided that the above
8 * copyright notice appear in all copies and that both the copyright notice
9 * and this permission notice appear in supporting documentation, and that
10 * the name of Silicon Graphics, Inc. not be used in advertising
11 * or publicity pertaining to distribution of the software without specific,
12 * written prior permission.
14 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
15 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
17 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
18 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
19 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
20 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
21 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
22 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
23 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
25 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
27 * US Government Users Restricted Rights
28 * Use, duplication, or disclosure by the Government is subject to
29 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
30 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
31 * clause at DFARS 252.227-7013 and/or in similar or successor
32 * clauses in the FAR or the DOD or NASA FAR Supplement.
33 * Unpublished-- rights reserved under the copyright laws of the
34 * United States. Contractor/manufacturer is Silicon Graphics,
35 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
37 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
41 * This program draws a NURBS surface in the shape of a
45 #include "glut_wrap.h"
47 GLfloat ctlpoints
[4][4][3];
53 * Initializes the control points of the surface to a small hill.
54 * The control points range from -3 to +3 in x, y, and z
56 static void init_surface(void)
59 for (u
= 0; u
< 4; u
++) {
60 for (v
= 0; v
< 4; v
++) {
61 ctlpoints
[u
][v
][0] = 2.0*((GLfloat
)u
- 1.5);
62 ctlpoints
[u
][v
][1] = 2.0*((GLfloat
)v
- 1.5);
64 if ( (u
== 1 || u
== 2) && (v
== 1 || v
== 2))
65 ctlpoints
[u
][v
][2] = 7.0;
67 ctlpoints
[u
][v
][2] = -3.0;
72 /* Initialize material property and depth buffer.
74 static void myinit(void)
76 GLfloat mat_diffuse
[] = { 0.7, 0.7, 0.7, 1.0 };
77 GLfloat mat_specular
[] = { 1.0, 1.0, 1.0, 1.0 };
78 GLfloat mat_shininess
[] = { 100.0 };
80 glClearColor (0.0, 0.0, 0.0, 1.0);
81 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, mat_diffuse
);
82 glMaterialfv(GL_FRONT
, GL_SPECULAR
, mat_specular
);
83 glMaterialfv(GL_FRONT
, GL_SHININESS
, mat_shininess
);
85 glEnable(GL_LIGHTING
);
88 glEnable(GL_DEPTH_TEST
);
89 glEnable(GL_AUTO_NORMAL
);
90 glEnable(GL_NORMALIZE
);
94 theNurb
= gluNewNurbsRenderer();
95 gluNurbsProperty(theNurb
, GLU_SAMPLING_TOLERANCE
, 25.0);
96 gluNurbsProperty(theNurb
, GLU_DISPLAY_MODE
, GLU_FILL
);
98 glMatrixMode(GL_MODELVIEW
);
100 glTranslatef (0.0, 0.0, -5.0);
103 static void display(void)
105 GLfloat knots
[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};
108 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
111 glRotatef(330.0, 1.,0.,0.);
112 glScalef (0.25, 0.25, 0.25);
114 gluBeginSurface(theNurb
);
115 gluNurbsSurface(theNurb
,
123 gluEndSurface(theNurb
);
127 glDisable(GL_LIGHTING
);
128 glColor3f(1.0, 1.0, 0.0);
132 glVertex3f(ctlpoints
[i
][j
][0], ctlpoints
[i
][j
][1], ctlpoints
[i
][j
][2]);
136 glEnable(GL_LIGHTING
);
143 static void reshape(int w
, int h
)
145 glViewport(0, 0, w
, h
);
146 glMatrixMode(GL_PROJECTION
);
148 gluPerspective (45.0, (GLdouble
)w
/(GLdouble
)h
, 3.0, 8.0);
150 glMatrixMode(GL_MODELVIEW
);
162 gluNurbsProperty(theNurb
, GLU_DISPLAY_MODE
, GLU_FILL
);
165 gluNurbsProperty(theNurb
, GLU_DISPLAY_MODE
, GLU_OUTLINE_POLYGON
);
178 glRotatef(lastx
- x
, 0, 1, 0);
186 mouse(int button
, int state
, int x
, int y
)
188 if (button
== GLUT_LEFT_BUTTON
) {
189 if (state
== GLUT_DOWN
) {
199 key(unsigned char k
, int x
, int y
)
202 case 27: /* Escape */
213 main(int argc
, char** argv
)
215 glutInit(&argc
, argv
);
216 glutInitDisplayMode(GLUT_DEPTH
| GLUT_DOUBLE
| GLUT_RGB
);
217 glutCreateWindow(argv
[0]);
219 glutReshapeFunc(reshape
);
220 glutDisplayFunc(display
);
221 glutCreateMenu(menu
);
222 glutAddMenuEntry("Show control points", 1);
223 glutAddMenuEntry("Hide control points", 0);
224 glutAddMenuEntry("Solid", 2);
225 glutAddMenuEntry("Wireframe", 3);
226 glutAttachMenu(GLUT_RIGHT_BUTTON
);
227 glutMouseFunc(mouse
);
228 glutMotionFunc(motion
);
229 glutKeyboardFunc(key
);
231 return 0; /* ANSI C requires main to return int. */