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.
37 static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
43 static const GLfloat verts[3][2] = {
48 static const GLfloat colors[3][3] = {
54 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
57 glRotatef(view_rotx, 1, 0, 0);
58 glRotatef(view_roty, 0, 1, 0);
59 glRotatef(view_rotz, 0, 0, 1);
62 glVertexPointer(2, GL_FLOAT, 0, verts);
63 glColorPointer(3, GL_FLOAT, 0, colors);
64 glEnableClientState(GL_VERTEX_ARRAY);
65 glEnableClientState(GL_COLOR_ARRAY);
67 glDrawArrays(GL_TRIANGLES, 0, 3);
69 glDisableClientState(GL_VERTEX_ARRAY);
70 glDisableClientState(GL_COLOR_ARRAY);
77 /* new window size or exposure */
79 reshape(int width, int height)
81 GLfloat ar = (GLfloat) width / (GLfloat) height;
83 glViewport(0, 0, (GLint) width, (GLint) height);
85 glMatrixMode(GL_PROJECTION);
87 glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
89 glMatrixMode(GL_MODELVIEW);
91 glTranslatef(0.0, 0.0, -10.0);
98 glClearColor(0.4, 0.4, 0.4, 0.0);
103 special_key(int special)
109 case EGLUT_KEY_RIGHT:
124 main(int argc, char *argv[])
126 eglutInitWindowSize(300, 300);
127 eglutInitAPIMask(EGLUT_OPENGL_BIT);
128 eglutInit(argc, argv);
130 eglutCreateWindow("egltri");
132 eglutReshapeFunc(reshape);
133 eglutDisplayFunc(draw);
134 eglutSpecialFunc(special_key);