2
/* Copyright (c) Mark J. Kilgard, 1994. */
5
* (c) Copyright 1993, Silicon Graphics, Inc.
7
* Permission to use, copy, modify, and distribute this software for
8
* any purpose and without fee is hereby granted, provided that the above
9
* copyright notice appear in all copies and that both the copyright notice
10
* and this permission notice appear in supporting documentation, and that
11
* the name of Silicon Graphics, Inc. not be used in advertising
12
* or publicity pertaining to distribution of the software without specific,
13
* written prior permission.
15
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
28
* US Government Users Restricted Rights
29
* Use, duplication, or disclosure by the Government is subject to
30
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
* clause at DFARS 252.227-7013 and/or in similar or successor
33
* clauses in the FAR or the DOD or NASA FAR Supplement.
34
* Unpublished-- rights reserved under the copyright laws of the
35
* United States. Contractor/manufacturer is Silicon Graphics,
36
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
38
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
42
* This program shows a NURBS (Non-uniform rational B-splines)
43
* surface, shaped like a heart.
48
#define S_NUMPOINTS 13
50
#define S_NUMKNOTS (S_NUMPOINTS + S_ORDER)
53
#define T_NUMKNOTS (T_NUMPOINTS + T_ORDER)
54
#define SQRT2 1.41421356237309504880
56
/* initialized local data */
58
GLfloat sknots[S_NUMKNOTS] =
59
{-1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0,
60
4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 9.0, 9.0};
61
GLfloat tknots[T_NUMKNOTS] = {1.0, 1.0, 1.0, 2.0, 2.0, 2.0};
63
GLfloat ctlpoints[S_NUMPOINTS][T_NUMPOINTS][4] = {
64
{ {4.,2.,2.,1.},{4.,1.6,2.5,1.},{4.,2.,3.0,1.} },
65
{ {5.,4.,2.,1.},{5.,4.,2.5,1.},{5.,4.,3.0,1.} },
66
{ {6.,5.,2.,1.},{6.,5.,2.5,1.},{6.,5.,3.0,1.} },
67
{ {SQRT2*6.,SQRT2*6.,SQRT2*2.,SQRT2},
68
{SQRT2*6.,SQRT2*6.,SQRT2*2.5,SQRT2},
69
{SQRT2*6.,SQRT2*6.,SQRT2*3.0,SQRT2} },
70
{ {5.2,6.7,2.,1.},{5.2,6.7,2.5,1.},{5.2,6.7,3.0,1.} },
71
{ {SQRT2*4.,SQRT2*6.,SQRT2*2.,SQRT2},
72
{SQRT2*4.,SQRT2*6.,SQRT2*2.5,SQRT2},
73
{SQRT2*4.,SQRT2*6.,SQRT2*3.0,SQRT2} },
74
{ {4.,5.2,2.,1.},{4.,4.6,2.5,1.},{4.,5.2,3.0,1.} },
75
{ {SQRT2*4.,SQRT2*6.,SQRT2*2.,SQRT2},
76
{SQRT2*4.,SQRT2*6.,SQRT2*2.5,SQRT2},
77
{SQRT2*4.,SQRT2*6.,SQRT2*3.0,SQRT2} },
78
{ {2.8,6.7,2.,1.},{2.8,6.7,2.5,1.},{2.8,6.7,3.0,1.} },
79
{ {SQRT2*2.,SQRT2*6.,SQRT2*2.,SQRT2},
80
{SQRT2*2.,SQRT2*6.,SQRT2*2.5,SQRT2},
81
{SQRT2*2.,SQRT2*6.,SQRT2*3.0,SQRT2} },
82
{ {2.,5.,2.,1.},{2.,5.,2.5,1.},{2.,5.,3.0,1.} },
83
{ {3.,4.,2.,1.},{3.,4.,2.5,1.},{3.,4.,3.0,1.} },
84
{ {4.,2.,2.,1.},{4.,1.6,2.5,1.},{4.,2.,3.0,1.} }
89
/* Initialize material property, light source, lighting model,
92
static void myinit(void)
94
GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
95
GLfloat mat_diffuse[] = { 1.0, 0.2, 1.0, 1.0 };
96
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
97
GLfloat mat_shininess[] = { 50.0 };
99
GLfloat light0_position[] = { 1.0, 0.1, 1.0, 0.0 };
100
GLfloat light1_position[] = { -1.0, 0.1, 1.0, 0.0 };
102
GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
104
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
105
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
106
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
107
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
108
glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
109
glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
110
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
112
glEnable(GL_LIGHTING);
115
glDepthFunc(GL_LESS);
116
glEnable(GL_DEPTH_TEST);
117
glEnable(GL_AUTO_NORMAL);
119
theNurb = gluNewNurbsRenderer();
121
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
122
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
125
static void display(void)
127
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
130
glTranslatef (4., 4.5, 2.5);
131
glRotatef (220.0, 1., 0., 0.);
132
glRotatef (115.0, 0., 1., 0.);
133
glTranslatef (-4., -4.5, -2.5);
135
gluBeginSurface(theNurb);
136
gluNurbsSurface(theNurb,
144
gluEndSurface(theNurb);
150
static void myReshape(int w, int h)
152
glViewport(0, 0, w, h);
153
glMatrixMode(GL_PROJECTION);
155
glFrustum(-1.0, 1.0, -1.5, 0.5, 0.8, 10.0);
157
glMatrixMode(GL_MODELVIEW);
159
gluLookAt(7.0,4.5,4.0, 4.5,4.5,2.0, 6.0,-3.0,2.0);
163
key(unsigned char k, int x, int y)
166
case 27: /* Escape */
176
* Open window with initial window size, title bar,
177
* RGBA display mode, and handle input events.
179
int main(int argc, char** argv)
181
glutInit(&argc, argv);
182
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
183
glutCreateWindow (argv[0]);
185
glutReshapeFunc (myReshape);
186
glutDisplayFunc(display);
187
glutKeyboardFunc(key);
189
return 0; /* ANSI C requires main to return int. */