~ubuntu-branches/ubuntu/oneiric/mesa-demos/oneiric

« back to all changes in this revision

Viewing changes to src/tests/unfilledclip.c

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2010-09-27 16:18:27 UTC
  • Revision ID: james.westby@ubuntu.com-20100927161827-1yfgolc1oy9sjhi8
Tags: upstream-8.0.1
Import upstream version 8.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2008 Intel Corporation
 
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 (including the next
 
12
 * paragraph) shall be included in all copies or substantial portions of the
 
13
 * Software.
 
14
 *
 
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.
 
22
 *
 
23
 * Authors:
 
24
 *    Eric Anholt <eric@anholt.net>
 
25
 *
 
26
 */
 
27
 
 
28
#include <stdlib.h>
 
29
#include <GL/glew.h>
 
30
#include <GL/glut.h>
 
31
 
 
32
static int win_width, win_height;
 
33
 
 
34
#if 0
 
35
static void
 
36
line(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
 
37
{
 
38
        glBegin(GL_LINES);
 
39
        glVertex2f(x1, y1);
 
40
        glVertex2f(x2, y2);
 
41
        glEnd();
 
42
}
 
43
#endif
 
44
 
 
45
static void
 
46
line3(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2)
 
47
{
 
48
        glBegin(GL_LINES);
 
49
        glVertex3f(x1, y1, z1);
 
50
        glVertex3f(x2, y2, z2);
 
51
        glEnd();
 
52
}
 
53
 
 
54
static void
 
55
display(void)
 
56
{
 
57
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
58
 
 
59
        glClearColor(0.0, 0.0, 0.0, 0.0);
 
60
        glClear(GL_COLOR_BUFFER_BIT);
 
61
 
 
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();
 
69
 
 
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();
 
77
 
 
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();
 
85
 
 
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();
 
93
 
 
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();
 
101
 
 
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();
 
109
 
 
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();
 
117
 
 
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();
 
123
 
 
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);
 
127
 
 
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();
 
150
 
 
151
        glutSwapBuffers();
 
152
}
 
153
 
 
154
static void
 
155
reshape(int width, int height)
 
156
{
 
157
        win_width = width;
 
158
        win_height = height;
 
159
        glViewport(0, 0, width, height);
 
160
 
 
161
        glMatrixMode(GL_PROJECTION);
 
162
        glLoadIdentity();
 
163
        glOrtho(0, win_width, 0, win_height, 0.0, -1.0);
 
164
 
 
165
        glMatrixMode(GL_MODELVIEW);
 
166
        glLoadIdentity();
 
167
        glTranslatef(.25, .25, 0);
 
168
}
 
169
 
 
170
static void key( unsigned char key, int x, int y )
 
171
{
 
172
        (void) x;
 
173
        (void) y;
 
174
 
 
175
        switch (key) {
 
176
        case 27: /* esc */
 
177
                exit(0);
 
178
                break;
 
179
        }
 
180
 
 
181
        glutPostRedisplay();
 
182
}
 
183
 
 
184
static void
 
185
init(void)
 
186
{
 
187
}
 
188
 
 
189
int
 
190
main(int argc, char *argv[])
 
191
{
 
192
        win_width = 200;
 
193
        win_height = 200;
 
194
 
 
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);
 
204
 
 
205
        init();
 
206
 
 
207
        glutMainLoop();
 
208
        return 0;
 
209
}