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
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
24 * Eric Anholt <eric@anholt.net>
30 #include "glut_wrap.h"
32 static int win_width
, win_height
;
36 line(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
46 line3(GLfloat x1
, GLfloat y1
, GLfloat z1
, GLfloat x2
, GLfloat y2
, GLfloat z2
)
49 glVertex3f(x1
, y1
, z1
);
50 glVertex3f(x2
, y2
, z2
);
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);
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);
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);
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);
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);
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);
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);
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);
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 */
135 glBegin(GL_TRIANGLES
); /* xmin, ymax */
136 glVertex2f(-5, win_height
- 20);
137 glVertex2f(20, win_height
- 20);
138 glVertex2f(20, win_height
+ 5);
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);
145 glBegin(GL_TRIANGLES
); /* xmax, ymin */
146 glVertex2f(win_width
+ 5, 20);
147 glVertex2f(win_width
- 20, 20);
148 glVertex2f(win_width
- 20, -5);
155 reshape(int width
, int height
)
159 glViewport(0, 0, width
, height
);
161 glMatrixMode(GL_PROJECTION
);
163 glOrtho(0, win_width
, 0, win_height
, 0.0, -1.0);
165 glMatrixMode(GL_MODELVIEW
);
167 glTranslatef(.25, .25, 0);
170 static void key( unsigned char key
, int x
, int y
)
190 main(int argc
, char *argv
[])
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]);
201 glutReshapeFunc(reshape
);
202 glutKeyboardFunc(key
);
203 glutDisplayFunc(display
);