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
36
#define VMAJOR_ORDER 2
37
#define VMINOR_ORDER 3
39
#define CMAJOR_ORDER 2
40
#define CMINOR_ORDER 2
42
#define TMAJOR_ORDER 2
43
#define TMINOR_ORDER 2
58
float rotX = 0.0, rotY = 0.0, translateZ = -1.0;
60
GLenum arrayType = ONE_D;
61
GLenum colorType = GL_FALSE;
62
GLenum textureType = GL_FALSE;
63
GLenum polygonFilled = GL_FALSE;
64
GLenum lighting = GL_FALSE;
65
GLenum mapPoint = GL_FALSE;
66
GLenum mapType = EVAL;
68
double point1[10*4] = {
80
double cpoint1[10*4] = {
91
double tpoint1[11*4] = {
103
double point2[2*3*4] = {
104
-0.5, -0.5, 0.5, 1.0,
107
-0.5, 0.5, -0.5, 1.0,
108
0.0, -1.0, -0.5, 1.0,
111
double cpoint2[2*2*4] = {
117
double tpoint2[2*2*2] = {
121
float textureImage[4*2*4] = {
133
static void Init(void)
135
static float ambient[] = {0.1, 0.1, 0.1, 1.0};
136
static float diffuse[] = {1.0, 1.0, 1.0, 1.0};
137
static float position[] = {0.0, 0.0, -150.0, 0.0};
138
static float front_mat_diffuse[] = {1.0, 0.2, 1.0, 1.0};
139
static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
140
static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
141
static float lmodel_twoside[] = {GL_TRUE};
142
static float decal[] = {GL_DECAL};
143
static float repeat[] = {GL_REPEAT};
144
static float nr[] = {GL_NEAREST};
148
glEnable(GL_DEPTH_TEST);
150
glMap1d(GL_MAP1_VERTEX_4, 0.0, 1.0, VDIM, VORDER, point1);
151
glMap1d(GL_MAP1_COLOR_4, 0.0, 1.0, CDIM, CORDER, cpoint1);
153
glMap2d(GL_MAP2_VERTEX_4, 0.0, 1.0, VMINOR_ORDER*VDIM, VMAJOR_ORDER, 0.0,
154
1.0, VDIM, VMINOR_ORDER, point2);
155
glMap2d(GL_MAP2_COLOR_4, 0.0, 1.0, CMINOR_ORDER*CDIM, CMAJOR_ORDER, 0.0,
156
1.0, CDIM, CMINOR_ORDER, cpoint2);
157
glMap2d(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, TMINOR_ORDER*TDIM,
158
TMAJOR_ORDER, 0.0, 1.0, TDIM, TMINOR_ORDER, tpoint2);
160
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
161
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
162
glLightfv(GL_LIGHT0, GL_POSITION, position);
164
glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
165
glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
167
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
168
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
170
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal);
171
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat);
172
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat);
173
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nr);
174
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nr);
175
glTexImage2D(GL_TEXTURE_2D, 0, 4, 2, 4, 0, GL_RGBA, GL_FLOAT,
176
(GLvoid *)textureImage);
179
static void DrawPoints1(void)
183
glColor3f(0.0, 1.0, 0.0);
186
for (i = 0; i < VORDER; i++) {
187
glVertex4dv(&point1[i*4]);
192
static void DrawPoints2(void)
196
glColor3f(1.0, 0.0, 1.0);
199
for (i = 0; i < VMAJOR_ORDER; i++) {
200
for (j = 0; j < VMINOR_ORDER; j++) {
201
glVertex4dv(&point2[i*4*VMINOR_ORDER+j*4]);
207
static void DrawMapEval1(float du)
211
glColor3f(1.0, 0.0, 0.0);
212
glBegin(GL_LINE_STRIP);
213
for (u = 0.0; u < 1.0; u += du) {
220
static void DrawMapEval2(float du, float dv)
224
glColor3f(1.0, 0.0, 0.0);
225
for (v = 0.0; v < 1.0; v += dv) {
226
glBegin(GL_QUAD_STRIP);
227
for (u = 0.0; u <= 1.0; u += du) {
229
tmp = (v + dv < 1.0) ? (v + dv) : 1.0;
230
glEvalCoord2d(u, tmp);
232
glEvalCoord2d(1.0, v);
233
glEvalCoord2d(1.0, v+dv);
238
static void RenderEval(void)
242
glEnable(GL_MAP1_COLOR_4);
243
glEnable(GL_MAP2_COLOR_4);
245
glDisable(GL_MAP1_COLOR_4);
246
glDisable(GL_MAP2_COLOR_4);
250
glEnable(GL_TEXTURE_2D);
251
glEnable(GL_MAP2_TEXTURE_COORD_2);
253
glDisable(GL_TEXTURE_2D);
254
glDisable(GL_MAP2_TEXTURE_COORD_2);
258
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
260
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
263
glShadeModel(GL_SMOOTH);
269
glDisable(GL_MAP2_VERTEX_4);
270
glEnable(GL_MAP1_VERTEX_4);
272
DrawMapEval1(0.1/VORDER);
275
glDisable(GL_MAP1_VERTEX_4);
276
glEnable(GL_MAP2_VERTEX_4);
278
DrawMapEval2(0.1/VMAJOR_ORDER,0.1/VMINOR_ORDER);
288
glDisable(GL_MAP2_VERTEX_4);
289
glEnable (GL_MAP1_VERTEX_4);
290
glColor3f(0.0, 0.0, 1.0);
291
glMapGrid1d(40, 0.0, 1.0);
294
glEvalMesh1(GL_POINT, 0, 40);
296
glEvalMesh1(GL_LINE, 0, 40);
301
glDisable(GL_MAP1_VERTEX_4);
302
glEnable(GL_MAP2_VERTEX_4);
303
glColor3f(0.0, 0.0, 1.0);
304
glMapGrid2d(20, 0.0, 1.0, 20, 0.0, 1.0);
307
glEvalMesh2(GL_POINT, 0, 20, 0, 20);
308
} else if (polygonFilled) {
309
glEvalMesh2(GL_FILL, 0, 20, 0, 20);
311
glEvalMesh2(GL_LINE, 0, 20, 0, 20);
323
static void Reshape(int width, int height)
326
glViewport(0, 0, (GLint)width, (GLint)height);
328
glMatrixMode(GL_PROJECTION);
330
glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 10.0);
331
glMatrixMode(GL_MODELVIEW);
334
static void Key2(int key, int x, int y)
356
static void Key(unsigned char key, int x, int y)
374
polygonFilled = !polygonFilled;
377
mapPoint = !mapPoint;
380
colorType = !colorType;
383
textureType = !textureType;
386
lighting =! lighting;
388
glEnable(GL_LIGHTING);
390
glEnable(GL_AUTO_NORMAL);
392
glDisable(GL_LIGHTING);
393
glDisable(GL_LIGHT0);
394
glDisable(GL_AUTO_NORMAL);
404
static void Draw(void)
407
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
411
glTranslatef(0.0, 0.0 , translateZ);
412
glRotatef(rotX, 1, 0, 0);
413
glRotatef(rotY, 0, 1, 0);
425
static GLenum Args(int argc, char **argv)
429
doubleBuffer = GL_FALSE;
431
for (i = 1; i < argc; i++) {
432
if (strcmp(argv[i], "-sb") == 0) {
433
doubleBuffer = GL_FALSE;
434
} else if (strcmp(argv[i], "-db") == 0) {
435
doubleBuffer = GL_TRUE;
437
printf("%s (Bad option).\n", argv[i]);
444
int main(int argc, char **argv)
448
glutInit(&argc, argv);
450
if (Args(argc, argv) == GL_FALSE) {
454
glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
456
type = GLUT_RGB | GLUT_DEPTH;
457
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
458
glutInitDisplayMode(type);
460
if (glutCreateWindow("Evaluator Test") == GL_FALSE) {
466
glutReshapeFunc(Reshape);
467
glutKeyboardFunc(Key);
468
glutSpecialFunc(Key2);
469
glutDisplayFunc(Draw);