2 * Copyright (C) 2008 Brian Paul All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Draw a triangle with X/EGL and OpenGL ES 1.x
28 #define USE_FIXED_POINT 0
34 #include <GLES/gl.h> /* use OpenGL ES 1.x */
35 #include <GLES/glext.h>
41 #define FLOAT_TO_FIXED(X) ((X) * 65535.0)
45 static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
52 static const GLfixed verts[3][2] = {
57 static const GLfixed colors[3][4] = {
58 { 65536, 0, 0, 65536 },
59 { 0, 65536, 0 , 65536},
60 { 0, 0, 65536 , 65536}
63 static const GLfloat verts[3][2] = {
68 static const GLfloat colors[3][4] = {
75 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
78 glRotatef(view_rotx, 1, 0, 0);
79 glRotatef(view_roty, 0, 1, 0);
80 glRotatef(view_rotz, 0, 0, 1);
84 glVertexPointer(2, GL_FIXED, 0, verts);
85 glColorPointer(4, GL_FIXED, 0, colors);
87 glVertexPointer(2, GL_FLOAT, 0, verts);
88 glColorPointer(4, GL_FLOAT, 0, colors);
90 glEnableClientState(GL_VERTEX_ARRAY);
91 glEnableClientState(GL_COLOR_ARRAY);
94 glDrawArrays(GL_TRIANGLES, 0, 3);
96 /* draw some points */
97 glPointSizex(FLOAT_TO_FIXED(15.5));
98 glDrawArrays(GL_POINTS, 0, 3);
100 glDisableClientState(GL_VERTEX_ARRAY);
101 glDisableClientState(GL_COLOR_ARRAY);
107 glGetFixedv(GL_POINT_SIZE, &size);
108 printf("GL_POINT_SIZE = 0x%x %f\n", size, size / 65536.0);
115 /* new window size or exposure */
117 reshape(int width, int height)
119 GLfloat ar = (GLfloat) width / (GLfloat) height;
121 glViewport(0, 0, (GLint) width, (GLint) height);
123 glMatrixMode(GL_PROJECTION);
125 #ifdef GL_VERSION_ES_CM_1_0
126 glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
128 glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
131 glMatrixMode(GL_MODELVIEW);
133 glTranslatef(0.0, 0.0, -10.0);
138 test_query_matrix(void)
140 PFNGLQUERYMATRIXXOESPROC procQueryMatrixx;
141 typedef void (*voidproc)();
142 GLfixed mantissa[16];
147 procQueryMatrixx = (PFNGLQUERYMATRIXXOESPROC) eglGetProcAddress("glQueryMatrixxOES");
148 assert(procQueryMatrixx);
149 /* Actually try out this one */
150 rv = (*procQueryMatrixx)(mantissa, exponent);
151 for (i = 0; i < 16; i++) {
153 printf("matrix[%d] invalid\n", i);
156 printf("matrix[%d] = %f * 2^(%d)\n", i, mantissa[i]/65536.0, exponent[i]);
159 assert(!eglGetProcAddress("glFoo"));
166 glClearColor(0.4, 0.4, 0.4, 0.0);
173 special_key(int special)
179 case EGLUT_KEY_RIGHT:
194 main(int argc, char *argv[])
196 eglutInitWindowSize(300, 300);
197 eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
198 eglutInit(argc, argv);
200 eglutCreateWindow("tri");
202 eglutReshapeFunc(reshape);
203 eglutDisplayFunc(draw);
204 eglutSpecialFunc(special_key);