WIP - port to Mali EGL
[mesa-demos/mali.git] / src / tests / unfilledclip.c
blob018e8de194fc2cd1484df34c062c07fb67212a1a
1 /*
2 * Copyright © 2008 Intel Corporation
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 #include <stdlib.h>
29 #include <GL/glew.h>
30 #include "glut_wrap.h"
32 static int win_width, win_height;
34 #if 0
35 static void
36 line(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
38 glBegin(GL_LINES);
39 glVertex2f(x1, y1);
40 glVertex2f(x2, y2);
41 glEnd();
43 #endif
45 static void
46 line3(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2)
48 glBegin(GL_LINES);
49 glVertex3f(x1, y1, z1);
50 glVertex3f(x2, y2, z2);
51 glEnd();
54 static void
55 display(void)
57 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
59 glClearColor(0.0, 0.0, 0.0, 0.0);
60 glClear(GL_COLOR_BUFFER_BIT);
62 glColor3f(1.0, 0.0, 0.0);
63 /* clipped along xmin */
64 glBegin(GL_TRIANGLES);
65 glVertex2f(-20, win_height / 2 - 20);
66 glVertex2f(20, win_height / 2);
67 glVertex2f(-20, win_height / 2 + 20);
68 glEnd();
70 glColor3f(0.0, 1.0, 0.0);
71 /* clipped along ymax */
72 glBegin(GL_TRIANGLES);
73 glVertex2f(win_height / 2 - 20, win_height + 20);
74 glVertex2f(win_height / 2, win_height - 20);
75 glVertex2f(win_height / 2 + 20, win_height + 20);
76 glEnd();
78 glColor3f(0.0, 0.0, 1.0);
79 /* clipped along xmax */
80 glBegin(GL_TRIANGLES);
81 glVertex2f(win_height + 20, win_height / 2 - 20);
82 glVertex2f(win_height - 20, win_height / 2);
83 glVertex2f(win_height + 20, win_height / 2 + 20);
84 glEnd();
86 glColor3f(1.0, 1.0, 1.0);
87 /* clipped along ymin */
88 glBegin(GL_TRIANGLES);
89 glVertex2f(win_height / 2 - 20, -20);
90 glVertex2f(win_height / 2, 20);
91 glVertex2f(win_height / 2 + 20, -20);
92 glEnd();
94 /* clipped along near */
95 glColor3f(1.0, 0.0, 1.0);
96 glBegin(GL_TRIANGLES);
97 glVertex3f(win_width / 2 - 20, win_height / 2 - 20, 0.5);
98 glVertex3f(win_width / 2 - 40, win_height / 2, -0.5);
99 glVertex3f(win_width / 2 - 20, win_height / 2 + 20, 0.5);
100 glEnd();
102 /* clipped along far */
103 glColor3f(0.0, 1.0, 1.0);
104 glBegin(GL_TRIANGLES);
105 glVertex3f(win_width / 2 + 20, win_height / 2 - 20, 0.5);
106 glVertex3f(win_width / 2 + 40, win_height / 2, 1.5);
107 glVertex3f(win_width / 2 + 20, win_height / 2 + 20, 0.5);
108 glEnd();
110 /* entirely clipped along near/far */
111 glColor3f(.5, .5, .5);
112 glBegin(GL_TRIANGLES);
113 glVertex3f(win_width / 2 - 20, win_height / 2 + 20, -0.5);
114 glVertex3f(win_width / 2, win_height / 2 + 40, -0.5);
115 glVertex3f(win_width / 2 + 20, win_height / 2 + 20, -0.5);
116 glEnd();
118 glBegin(GL_TRIANGLES);
119 glVertex3f(win_width / 2 - 20, win_height / 2 - 20, 1.5);
120 glVertex3f(win_width / 2, win_height / 2 - 40, 1.5);
121 glVertex3f(win_width / 2 + 20, win_height / 2 - 20, 1.5);
122 glEnd();
124 glColor3f(.5, .5, .5);
125 line3(win_width / 2, win_height / 2 - 20, 1.5,
126 win_width / 2, win_height / 2 + 20, 1.5);
128 glColor3f(1.0, 1.0, 0.0);
129 /* clipped along both x and y limits */
130 glBegin(GL_TRIANGLES); /* xmin, ymin */
131 glVertex2f(-5, 20);
132 glVertex2f(20, 20);
133 glVertex2f(20, -5);
134 glEnd();
135 glBegin(GL_TRIANGLES); /* xmin, ymax */
136 glVertex2f(-5, win_height - 20);
137 glVertex2f(20, win_height - 20);
138 glVertex2f(20, win_height + 5);
139 glEnd();
140 glBegin(GL_TRIANGLES); /* xmax, ymax */
141 glVertex2f(win_width - 20, win_height + 5);
142 glVertex2f(win_width - 20, win_height - 20);
143 glVertex2f(win_width + 5, win_height - 20);
144 glEnd();
145 glBegin(GL_TRIANGLES); /* xmax, ymin */
146 glVertex2f(win_width + 5, 20);
147 glVertex2f(win_width - 20, 20);
148 glVertex2f(win_width - 20, -5);
149 glEnd();
151 glutSwapBuffers();
154 static void
155 reshape(int width, int height)
157 win_width = width;
158 win_height = height;
159 glViewport(0, 0, width, height);
161 glMatrixMode(GL_PROJECTION);
162 glLoadIdentity();
163 glOrtho(0, win_width, 0, win_height, 0.0, -1.0);
165 glMatrixMode(GL_MODELVIEW);
166 glLoadIdentity();
167 glTranslatef(.25, .25, 0);
170 static void key( unsigned char key, int x, int y )
172 (void) x;
173 (void) y;
175 switch (key) {
176 case 27: /* esc */
177 exit(0);
178 break;
181 glutPostRedisplay();
184 static void
185 init(void)
190 main(int argc, char *argv[])
192 win_width = 200;
193 win_height = 200;
195 glutInit(&argc, argv);
196 glutInitWindowPosition(0, 0);
197 glutInitWindowSize(win_width, win_height);
198 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
199 glutCreateWindow(argv[0]);
200 glewInit();
201 glutReshapeFunc(reshape);
202 glutKeyboardFunc(key);
203 glutDisplayFunc(display);
205 init();
207 glutMainLoop();
208 return 0;