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.
41 * This program uses evaluators to generate a curved
42 * surface and automatically generated texture coordinates.
49 GLfloat ctrlpoints
[4][4][3] = {
50 {{ -1.5, -1.5, 4.0}, { -0.5, -1.5, 2.0},
51 {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}},
52 {{ -1.5, -0.5, 1.0}, { -0.5, -0.5, 3.0},
53 {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}},
54 {{ -1.5, 0.5, 4.0}, { -0.5, 0.5, 0.0},
55 {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}},
56 {{ -1.5, 1.5, -2.0}, { -0.5, 1.5, -2.0},
57 {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}}
60 GLfloat texpts
[2][2][2] = {{{0.0, 0.0}, {0.0, 1.0}},
61 {{1.0, 0.0}, {1.0, 1.0}}};
63 static void display(void)
65 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
66 glColor3f(1.0, 1.0, 1.0);
67 glEvalMesh2(GL_FILL
, 0, 20, 0, 20);
72 #define imageHeight 64
73 GLubyte image
[3*imageWidth
*imageHeight
];
75 static void makeImage(void)
80 for (i
= 0; i
< imageWidth
; i
++) {
81 ti
= 2.0*3.14159265*i
/imageWidth
;
82 for (j
= 0; j
< imageHeight
; j
++) {
83 tj
= 2.0*3.14159265*j
/imageHeight
;
85 image
[3*(imageHeight
*i
+j
)] = (GLubyte
) 127*(1.0+sin(ti
));
86 image
[3*(imageHeight
*i
+j
)+1] = (GLubyte
) 127*(1.0+cos(2*tj
));
87 image
[3*(imageHeight
*i
+j
)+2] = (GLubyte
) 127*(1.0+cos(ti
+tj
));
92 static void myinit(void)
94 glMap2f(GL_MAP2_VERTEX_3
, 0, 1, 3, 4,
95 0, 1, 12, 4, &ctrlpoints
[0][0][0]);
96 glMap2f(GL_MAP2_TEXTURE_COORD_2
, 0, 1, 2, 2,
97 0, 1, 4, 2, &texpts
[0][0][0]);
98 glEnable(GL_MAP2_TEXTURE_COORD_2
);
99 glEnable(GL_MAP2_VERTEX_3
);
100 glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
102 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
103 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
104 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
105 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
106 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
107 glTexImage2D(GL_TEXTURE_2D
, 0, 3, imageWidth
, imageHeight
, 0,
108 GL_RGB
, GL_UNSIGNED_BYTE
, image
);
109 glEnable(GL_TEXTURE_2D
);
110 glEnable(GL_DEPTH_TEST
);
111 glEnable(GL_NORMALIZE
);
112 glShadeModel (GL_FLAT
);
115 static void myReshape(int w
, int h
)
117 glViewport(0, 0, w
, h
);
118 glMatrixMode(GL_PROJECTION
);
121 glOrtho(-4.0, 4.0, -4.0*(GLfloat
)h
/(GLfloat
)w
,
122 4.0*(GLfloat
)h
/(GLfloat
)w
, -4.0, 4.0);
124 glOrtho(-4.0*(GLfloat
)w
/(GLfloat
)h
,
125 4.0*(GLfloat
)w
/(GLfloat
)h
, -4.0, 4.0, -4.0, 4.0);
126 glMatrixMode(GL_MODELVIEW
);
128 glRotatef(85.0, 1.0, 1.0, 1.0);
132 key(unsigned char k
, int x
, int y
)
135 case 27: /* Escape */
144 int main(int argc
, char** argv
)
146 glutInit(&argc
, argv
);
147 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
148 glutCreateWindow (argv
[0]);
150 glutReshapeFunc (myReshape
);
151 glutDisplayFunc(display
);
152 glutKeyboardFunc(key
);
154 return 0; /* ANSI C requires main to return int. */