2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
39 #define S_NUMPOINTS 13
41 #define S_NUMKNOTS (S_NUMPOINTS + S_ORDER)
44 #define T_NUMKNOTS (T_NUMPOINTS + T_ORDER)
45 #define SQRT_TWO 1.41421356237309504880
48 typedef INREAL Point
[4];
54 GLint rotX
= 40, rotY
= 40;
55 INREAL sknots
[S_NUMKNOTS
] = {
56 -1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0,
57 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 9.0, 9.0
59 INREAL tknots
[T_NUMKNOTS
] = {
60 1.0, 1.0, 1.0, 2.0, 2.0, 2.0
62 Point ctlpoints
[S_NUMPOINTS
][T_NUMPOINTS
] = {
98 SQRT_TWO
*6.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
101 SQRT_TWO
*6.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
104 SQRT_TWO
*6.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
120 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
123 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
126 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
142 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
145 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
148 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
164 SQRT_TWO
*2.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
167 SQRT_TWO
*2.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
170 SQRT_TWO
*2.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
207 GLUnurbsObj
*theNurbs
;
210 static void CALLBACK
ErrorCallback(GLenum which
)
213 if (which
!= expectedError
) {
214 fprintf(stderr
, "Unexpected error occured (%d):\n", which
);
215 fprintf(stderr
, " %s\n", (char *) gluErrorString(which
));
219 typedef void (GLAPIENTRY
*callback_t
)();
221 static void Init(void)
224 theNurbs
= gluNewNurbsRenderer();
225 gluNurbsCallback(theNurbs
, GLU_ERROR
, (callback_t
) ErrorCallback
);
227 gluNurbsProperty(theNurbs
, GLU_SAMPLING_TOLERANCE
, 15.0);
228 gluNurbsProperty(theNurbs
, GLU_DISPLAY_MODE
, GLU_OUTLINE_PATCH
);
230 expectedError
= GLU_INVALID_ENUM
;
231 gluNurbsProperty(theNurbs
, ~0, 15.0);
232 expectedError
= GLU_NURBS_ERROR13
;
233 gluEndSurface(theNurbs
);
236 glColor3f(1.0, 1.0, 1.0);
239 static void Reshape(int width
, int height
)
242 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
244 glMatrixMode(GL_PROJECTION
);
246 glFrustum(-2.0, 2.0, -2.0, 2.0, 0.8, 10.0);
247 gluLookAt(7.0, 4.5, 4.0, 4.5, 4.5, 2.5, 6.0, -3.0, 2.0);
248 glMatrixMode(GL_MODELVIEW
);
251 static void Key2(int key
, int x
, int y
)
274 static void Key(unsigned char key
, int x
, int y
)
283 static void Draw(void)
286 glClear(GL_COLOR_BUFFER_BIT
);
290 glTranslatef(4.0, 4.5, 2.5);
291 glRotatef(rotY
, 1, 0, 0);
292 glRotatef(rotX
, 0, 1, 0);
293 glTranslatef(-4.0, -4.5, -2.5);
295 gluBeginSurface(theNurbs
);
296 gluNurbsSurface(theNurbs
, S_NUMKNOTS
, sknots
, T_NUMKNOTS
, tknots
,
297 4*T_NUMPOINTS
, 4, &ctlpoints
[0][0][0], S_ORDER
,
298 T_ORDER
, GL_MAP2_VERTEX_4
);
299 gluEndSurface(theNurbs
);
310 static GLenum
Args(int argc
, char **argv
)
314 doubleBuffer
= GL_FALSE
;
316 for (i
= 1; i
< argc
; i
++) {
317 if (strcmp(argv
[i
], "-sb") == 0) {
318 doubleBuffer
= GL_FALSE
;
319 } else if (strcmp(argv
[i
], "-db") == 0) {
320 doubleBuffer
= GL_TRUE
;
322 printf("%s (Bad option).\n", argv
[i
]);
329 int main(int argc
, char **argv
)
333 glutInit(&argc
, argv
);
335 if (Args(argc
, argv
) == GL_FALSE
) {
339 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
342 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
343 glutInitDisplayMode(type
);
345 if (glutCreateWindow("NURBS Test") == GL_FALSE
) {
351 glutReshapeFunc(Reshape
);
352 glutKeyboardFunc(Key
);
353 glutSpecialFunc(Key2
);
354 glutDisplayFunc(Draw
);