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
29 #include "glut_wrap.h"
34 #define S_NUMPOINTS 13
36 #define S_NUMKNOTS (S_NUMPOINTS + S_ORDER)
39 #define T_NUMKNOTS (T_NUMPOINTS + T_ORDER)
40 #define SQRT_TWO 1.41421356237309504880
43 typedef INREAL Point
[4];
49 GLint rotX
= 40, rotY
= 40;
50 INREAL sknots
[S_NUMKNOTS
] = {
51 -1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0,
52 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 9.0, 9.0
54 INREAL tknots
[T_NUMKNOTS
] = {
55 1.0, 1.0, 1.0, 2.0, 2.0, 2.0
57 Point ctlpoints
[S_NUMPOINTS
][T_NUMPOINTS
] = {
93 SQRT_TWO
*6.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
96 SQRT_TWO
*6.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
99 SQRT_TWO
*6.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
115 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
118 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
121 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
137 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
140 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
143 SQRT_TWO
*4.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
159 SQRT_TWO
*2.0, SQRT_TWO
*6.0, SQRT_TWO
*2.0, SQRT_TWO
162 SQRT_TWO
*2.0, SQRT_TWO
*6.0, SQRT_TWO
*2.5, SQRT_TWO
165 SQRT_TWO
*2.0, SQRT_TWO
*6.0, SQRT_TWO
*3.0, SQRT_TWO
202 GLUnurbsObj
*theNurbs
;
205 static void GLAPIENTRY
ErrorCallback(GLenum which
)
208 if (which
!= expectedError
) {
209 fprintf(stderr
, "Unexpected error occured (%d):\n", which
);
210 fprintf(stderr
, " %s\n", (char *) gluErrorString(which
));
214 static void Init(void)
217 theNurbs
= gluNewNurbsRenderer();
218 gluNurbsCallback(theNurbs
, GLU_ERROR
, ErrorCallback
);
220 gluNurbsProperty(theNurbs
, GLU_SAMPLING_TOLERANCE
, 15.0);
221 gluNurbsProperty(theNurbs
, GLU_DISPLAY_MODE
, GLU_OUTLINE_PATCH
);
223 expectedError
= GLU_INVALID_ENUM
;
224 gluNurbsProperty(theNurbs
, ~0, 15.0);
225 expectedError
= GLU_NURBS_ERROR13
;
226 gluEndSurface(theNurbs
);
229 glColor3f(1.0, 1.0, 1.0);
232 static void Reshape(int width
, int height
)
235 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
237 glMatrixMode(GL_PROJECTION
);
239 glFrustum(-2.0, 2.0, -2.0, 2.0, 0.8, 10.0);
240 gluLookAt(7.0, 4.5, 4.0, 4.5, 4.5, 2.5, 6.0, -3.0, 2.0);
241 glMatrixMode(GL_MODELVIEW
);
244 static void Key2(int key
, int x
, int y
)
267 static void Key(unsigned char key
, int x
, int y
)
276 static void Draw(void)
279 glClear(GL_COLOR_BUFFER_BIT
);
283 glTranslatef(4.0, 4.5, 2.5);
284 glRotatef(rotY
, 1, 0, 0);
285 glRotatef(rotX
, 0, 1, 0);
286 glTranslatef(-4.0, -4.5, -2.5);
288 gluBeginSurface(theNurbs
);
289 gluNurbsSurface(theNurbs
, S_NUMKNOTS
, sknots
, T_NUMKNOTS
, tknots
,
290 4*T_NUMPOINTS
, 4, &ctlpoints
[0][0][0], S_ORDER
,
291 T_ORDER
, GL_MAP2_VERTEX_4
);
292 gluEndSurface(theNurbs
);
303 static GLenum
Args(int argc
, char **argv
)
307 doubleBuffer
= GL_FALSE
;
309 for (i
= 1; i
< argc
; i
++) {
310 if (strcmp(argv
[i
], "-sb") == 0) {
311 doubleBuffer
= GL_FALSE
;
312 } else if (strcmp(argv
[i
], "-db") == 0) {
313 doubleBuffer
= GL_TRUE
;
315 printf("%s (Bad option).\n", argv
[i
]);
322 int main(int argc
, char **argv
)
326 glutInit(&argc
, argv
);
328 if (Args(argc
, argv
) == GL_FALSE
) {
332 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
335 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
336 glutInitDisplayMode(type
);
338 if (glutCreateWindow("NURBS Test") == GL_FALSE
) {
344 glutReshapeFunc(Reshape
);
345 glutKeyboardFunc(Key
);
346 glutSpecialFunc(Key2
);
347 glutDisplayFunc(Draw
);