]> git.cworth.org Git - apitrace-tests/blob - apps/egl/gl/tri.c
Automate egl_tri test.
[apitrace-tests] / apps / egl / gl / tri.c
1 /*
2  * Copyright (C) 2008  Brian Paul   All Rights Reserved.
3  * 
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:
10  * 
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  * 
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.
20  */
21
22 /*
23  * Draw a triangle with X/EGL.
24  * Brian Paul
25  * 3 June 2008
26  */
27
28
29 #include <math.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <GL/gl.h>
33
34 #include "eglut.h"
35
36
37 static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
38
39
40 static void
41 idle(void)
42 {
43    exit(0);
44 }
45
46 static void
47 draw(void)
48 {
49    static const GLfloat verts[3][2] = {
50       { -1, -1 },
51       {  1, -1 },
52       {  0,  1 }
53    };
54    static const GLfloat colors[3][3] = {
55       { 1, 0, 0 },
56       { 0, 1, 0 },
57       { 0, 0, 1 }
58    };
59
60    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
61
62    glPushMatrix();
63    glRotatef(view_rotx, 1, 0, 0);
64    glRotatef(view_roty, 0, 1, 0);
65    glRotatef(view_rotz, 0, 0, 1);
66
67    {
68       glVertexPointer(2, GL_FLOAT, 0, verts);
69       glColorPointer(3, GL_FLOAT, 0, colors);
70       glEnableClientState(GL_VERTEX_ARRAY);
71       glEnableClientState(GL_COLOR_ARRAY);
72
73       glDrawArrays(GL_TRIANGLES, 0, 3);
74
75       glDisableClientState(GL_VERTEX_ARRAY);
76       glDisableClientState(GL_COLOR_ARRAY);
77    }
78
79    glPopMatrix();
80
81    eglutIdleFunc(idle);
82 }
83
84
85 /* new window size or exposure */
86 static void
87 reshape(int width, int height)
88 {
89    GLfloat ar = (GLfloat) width / (GLfloat) height;
90
91    glViewport(0, 0, (GLint) width, (GLint) height);
92
93    glMatrixMode(GL_PROJECTION);
94    glLoadIdentity();
95    glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
96    
97    glMatrixMode(GL_MODELVIEW);
98    glLoadIdentity();
99    glTranslatef(0.0, 0.0, -10.0);
100 }
101
102
103 static void
104 init(void)
105 {
106    glClearColor(0.4, 0.4, 0.4, 0.0);
107 }
108
109
110 static void
111 special_key(int special)
112 {
113    switch (special) {
114    case EGLUT_KEY_LEFT:
115       view_roty += 5.0;
116       break;
117    case EGLUT_KEY_RIGHT:
118       view_roty -= 5.0;
119       break;
120    case EGLUT_KEY_UP:
121       view_rotx += 5.0;
122       break;
123    case EGLUT_KEY_DOWN:
124       view_rotx -= 5.0;
125       break;
126    default:
127       break;
128    }
129 }
130
131 int
132 main(int argc, char *argv[])
133 {
134    eglutInitWindowSize(300, 300);
135    eglutInitAPIMask(EGLUT_OPENGL_BIT);
136    eglutInit(argc, argv);
137
138    eglutCreateWindow("egltri");
139
140    eglutReshapeFunc(reshape);
141    eglutDisplayFunc(draw);
142    eglutSpecialFunc(special_key);
143
144    init();
145
146    eglutMainLoop();
147
148    return 0;
149 }