Revert "wglgears: show stereo-option in usage"
[mesa-demos.git] / src / samples / nurb.c
blob5d6df8cef09d3ad9e69bc57147d77c3ed02755ab
1 /*
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
13 * ANY KIND,
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
22 * OF THIS SOFTWARE.
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <math.h>
29 #include "glut_wrap.h"
32 #define INREAL float
34 #define S_NUMPOINTS 13
35 #define S_ORDER 3
36 #define S_NUMKNOTS (S_NUMPOINTS + S_ORDER)
37 #define T_NUMPOINTS 3
38 #define T_ORDER 3
39 #define T_NUMKNOTS (T_NUMPOINTS + T_ORDER)
40 #define SQRT_TWO 1.41421356237309504880
43 typedef INREAL Point[4];
46 GLenum doubleBuffer;
48 GLenum expectedError;
49 GLint rotX = 40, rotY = 40;
50 INREAL sknots[S_NUMKNOTS] = {
51 -1.0, -1.0, -1.0, 0.0, 1.0, 2.0,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QRT_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
170 2.0, 5.0, 2.0, 1.0
173 2.0, 5.0, 2.5, 1.0
176 2.0, 5.0, 3.0, 1.0
181 3.0, 4.0, 2.0, 1.0
184 3.0, 4.0, 2.5, 1.0
187 3.0, 4.0, 3.0, 1.0
192 4.0, 2.0, 2.0, 1.0
195 4.0, 1.6, 2.5, 1.0
198 4.0, 2.0, 3.0, 1.0
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);
227 expectedError = 0;
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);
238 glLoadIdentity();
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)
247 switch (key) {
248 case GLUT_KEY_DOWN:
249 rotX -= 5;
250 break;
251 case GLUT_KEY_UP:
252 rotX += 5;
253 break;
254 case GLUT_KEY_LEFT:
255 rotY -= 5;
256 break;
257 case GLUT_KEY_RIGHT:
258 rotY += 5;
259 break;
260 default:
261 return;
264 glutPostRedisplay();
267 static void Key(unsigned char key, int x, int y)
270 switch (key) {
271 case 27:
272 exit(1);
276 static void Draw(void)
279 glClear(GL_COLOR_BUFFER_BIT);
281 glPushMatrix();
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);
294 glPopMatrix();
296 glFlush();
298 if (doubleBuffer) {
299 glutSwapBuffers();
303 static GLenum Args(int argc, char **argv)
305 GLint i;
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;
314 } else {
315 printf("%s (Bad option).\n", argv[i]);
316 return GL_FALSE;
319 return GL_TRUE;
322 int main(int argc, char **argv)
324 GLenum type;
326 glutInit(&argc, argv);
328 if (Args(argc, argv) == GL_FALSE) {
329 exit(1);
332 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
334 type = GLUT_RGB;
335 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
336 glutInitDisplayMode(type);
338 if (glutCreateWindow("NURBS Test") == GL_FALSE) {
339 exit(1);
342 Init();
344 glutReshapeFunc(Reshape);
345 glutKeyboardFunc(Key);
346 glutSpecialFunc(Key2);
347 glutDisplayFunc(Draw);
348 glutMainLoop();
349 return 0;