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>
31 static int win_width
, win_height
;
34 line(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
43 line3(GLfloat x1
, GLfloat y1
, GLfloat z1
, GLfloat x2
, GLfloat y2
, GLfloat z2
)
46 glVertex3f(x1
, y1
, z1
);
47 glVertex3f(x2
, y2
, z2
);
54 glClearColor(0.0, 0.0, 0.0, 0.0);
55 glClear(GL_COLOR_BUFFER_BIT
);
57 glColor3f(1.0, 0.0, 0.0);
58 /* 2 lines clipped along xmin */
59 line(-20, win_height
/ 2 - 20,
60 20, win_height
/ 2 - 20);
61 line( 20, win_height
/ 2 + 20,
62 -20, win_height
/ 2 + 20);
64 glColor3f(0.0, 1.0, 0.0);
65 /* 2 lines clipped along ymax */
66 line(win_width
/ 2 - 20, win_height
+ 20,
67 win_width
/ 2 - 20, win_height
- 20);
68 line(win_width
/ 2 + 20, win_height
- 20,
69 win_width
/ 2 + 20, win_height
+ 20);
71 glColor3f(0.0, 0.0, 1.0);
72 /* 2 lines clipped along xmax */
73 line(win_width
- 20, win_height
/ 2 - 20,
74 win_width
+ 20, win_height
/ 2 - 20);
75 line(win_width
+ 20, win_height
/ 2 + 20,
76 win_width
- 20, win_height
/ 2 + 20);
78 glColor3f(1.0, 1.0, 1.0);
79 /* 2 lines clipped along ymin */
80 line(win_width
/ 2 - 20, 20,
81 win_width
/ 2 - 20, -20);
82 line(win_width
/ 2 + 20, -20,
83 win_width
/ 2 + 20, 20);
85 /* 2 lines clipped along near */
86 glColor3f(1.0, 0.0, 1.0);
87 line3(win_width
/ 2 - 20 - 20, win_height
/ 2, 0.5,
88 win_width
/ 2 - 20 + 20, win_height
/ 2, -0.5);
89 line3(win_width
/ 2 - 20, win_height
/ 2 - 20, -0.5,
90 win_width
/ 2 - 20, win_height
/ 2 + 20, 0.5);
92 /* 2 lines clipped along far */
93 glColor3f(0.0, 1.0, 1.0);
94 line3(win_width
/ 2 + 20 - 20, win_height
/ 2, 1.5,
95 win_width
/ 2 + 20 + 20, win_height
/ 2, 0.5);
96 line3(win_width
/ 2 + 20, win_height
/ 2 - 20, 0.5,
97 win_width
/ 2 + 20, win_height
/ 2 + 20, 1.5);
99 /* entirely clipped along near/far */
100 glColor3f(.5, .5, .5);
101 line3(win_width
/ 2, win_height
/ 2 - 20, -0.5,
102 win_width
/ 2, win_height
/ 2 + 20, -0.5);
103 glColor3f(.5, .5, .5);
104 line3(win_width
/ 2, win_height
/ 2 - 20, 1.5,
105 win_width
/ 2, win_height
/ 2 + 20, 1.5);
107 glColor3f(1.0, 1.0, 0.0);
108 /* lines clipped along both x and y limits */
110 20, -5); /* xmin, ymin */
111 line(-5, win_height
- 20,
112 20, win_height
+ 5); /* xmin, ymax */
113 line(win_width
- 20, -5,
114 win_width
+ 5, 20); /* xmax, ymin */
115 line(win_width
- 20, win_height
+ 5,
116 win_width
+ 5, win_height
- 20); /* xmax, ymax */
122 reshape(int width
, int height
)
126 glViewport(0, 0, width
, height
);
128 glMatrixMode(GL_PROJECTION
);
130 glOrtho(0, win_width
, 0, win_height
, 0.0, -1.0);
132 glMatrixMode(GL_MODELVIEW
);
134 glTranslatef(.25, .25, 0);
137 static void key( unsigned char key
, int x
, int y
)
157 main(int argc
, char *argv
[])
162 glutInit(&argc
, argv
);
163 glutInitWindowPosition(0, 0);
164 glutInitWindowSize(win_width
, win_height
);
165 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
166 glutCreateWindow(argv
[0]);
167 glutReshapeFunc(reshape
);
168 glutKeyboardFunc(key
);
169 glutDisplayFunc(display
);