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
28 #include <glad/glad.h>
29 #include "glut_wrap.h"
34 GLfloat position
[NR_VERTS
][4];
35 GLubyte color
[NR_VERTS
][4];
36 GLfloat tex0
[NR_VERTS
][2];
37 GLfloat tex1
[NR_VERTS
][2];
40 { { 0.9, -0.9, 0.0, 1.0 },
41 { 0.9, 0.9, 0.0, 1.0 },
42 { -0.9, 0.9, 0.0, 1.0 },
43 { -0.9, -0.9, 0.0, 1.0 } },
45 { { 0x00, 0x00, 0xff, 0x00 },
46 { 0x00, 0xff, 0x00, 0x00 },
47 { 0xff, 0x00, 0x00, 0x00 },
48 { 0xff, 0xff, 0xff, 0x00 }
63 GLuint indices
[] = { 0, 1, 2, 3 };
65 GLuint arrayObj
, elementObj
;
71 #define Offset(ptr, member) (void *)((const char *)&((ptr)->member) - (const char *)(ptr))
73 static void Init(void)
77 fprintf(stderr
, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
78 fprintf(stderr
, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
79 fprintf(stderr
, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
82 glClearColor(0.0, 0.0, 1.0, 0.0);
84 glGenTextures(2, texObj
);
88 GLubyte tex2d
[SIZE
][SIZE
][3];
91 for (s
= 0; s
< SIZE
; s
++) {
92 for (t
= 0; t
< SIZE
; t
++) {
93 tex2d
[t
][s
][0] = s
*255/(SIZE
-1);
94 tex2d
[t
][s
][1] = t
*255/(SIZE
-1);
99 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
100 glActiveTextureARB(GL_TEXTURE0_ARB
);
101 glBindTexture(GL_TEXTURE_2D
, texObj
[0]);
104 glTexImage2D(GL_TEXTURE_2D
, 0, 3, SIZE
, SIZE
, 0,
105 GL_RGB
, GL_UNSIGNED_BYTE
, tex2d
);
107 glEnable(GL_TEXTURE_2D
);
108 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
109 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_REPEAT
);
110 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
111 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
113 glPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
117 GLubyte tex2d
[SIZE
][SIZE
][3];
120 for (s
= 0; s
< SIZE
; s
++) {
121 for (t
= 0; t
< SIZE
; t
++) {
122 GLboolean on
= ((s
/4) ^ (t
/4)) & 1;
123 tex2d
[t
][s
][0] = on
? 128 : 0;
124 tex2d
[t
][s
][1] = on
? 128 : 0;
125 tex2d
[t
][s
][2] = on
? 128 : 0;
129 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
130 glActiveTextureARB(GL_TEXTURE1_ARB
);
131 glBindTexture(GL_TEXTURE_2D
, texObj
[1]);
133 glTexImage2D(GL_TEXTURE_2D
, 0, 3, SIZE
, SIZE
, 0,
134 GL_RGB
, GL_UNSIGNED_BYTE
, tex2d
);
136 glEnable(GL_TEXTURE_2D
);
137 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_ADD
);
138 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_REPEAT
);
139 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
140 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
142 glPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
145 glActiveTextureARB( GL_TEXTURE0_ARB
);
150 glGenBuffersARB(1, &arrayObj
);
151 glGenBuffersARB(1, &elementObj
);
153 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, arrayObj
);
154 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, elementObj
);
156 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
), &verts
, GL_STATIC_DRAW_ARB
);
157 glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, sizeof(indices
), indices
, GL_STATIC_DRAW_ARB
);
159 glEnableClientState( GL_VERTEX_ARRAY
);
160 glVertexPointer( 4, GL_FLOAT
, 0, Offset(&verts
, position
) );
162 glEnableClientState( GL_COLOR_ARRAY
);
163 glColorPointer( 4, GL_UNSIGNED_BYTE
, 0, Offset(&verts
, color
) );
165 glClientActiveTextureARB( GL_TEXTURE0_ARB
);
166 glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
167 glTexCoordPointer( 2, GL_FLOAT
, 0, Offset(&verts
, tex0
) );
169 glClientActiveTextureARB( GL_TEXTURE1_ARB
);
170 glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
171 glTexCoordPointer( 2, GL_FLOAT
, 0, Offset(&verts
, tex1
) );
173 glClientActiveTextureARB( GL_TEXTURE0_ARB
);
177 static void Reshape(int width
, int height
)
180 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
182 glMatrixMode(GL_PROJECTION
);
184 /* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
185 glMatrixMode(GL_MODELVIEW
);
188 static void Key(unsigned char key
, int x
, int y
)
201 static void Draw(void)
203 glClear(GL_COLOR_BUFFER_BIT
);
205 glDrawElements( GL_TRIANGLES
, 3, GL_UNSIGNED_INT
, NULL
);
214 static GLenum
Args(int argc
, char **argv
)
218 doubleBuffer
= GL_FALSE
;
220 for (i
= 1; i
< argc
; i
++) {
221 if (strcmp(argv
[i
], "-sb") == 0) {
222 doubleBuffer
= GL_FALSE
;
223 } else if (strcmp(argv
[i
], "-db") == 0) {
224 doubleBuffer
= GL_TRUE
;
226 fprintf(stderr
, "%s (Bad option).\n", argv
[i
]);
233 int main(int argc
, char **argv
)
237 glutInit(&argc
, argv
);
239 if (Args(argc
, argv
) == GL_FALSE
) {
243 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
245 type
= GLUT_RGB
| GLUT_ALPHA
;
246 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
247 glutInitDisplayMode(type
);
249 if (glutCreateWindow(*argv
) == GL_FALSE
) {
256 glutReshapeFunc(Reshape
);
257 glutKeyboardFunc(Key
);
258 glutDisplayFunc(Draw
);