radeon/r200/r300: cleanup some of the renderbuffer code
[mesa.git] / progs / tests / texline.c
1
2 /*
3 * Test textured lines.
4 *
5 * Brian Paul
6 * September 2000
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <math.h>
12 #include <GL/glut.h>
13 #include "../util/readtex.c" /* I know, this is a hack. */
14
15 #define TEXTURE_FILE "../images/girl.rgb"
16
17 static GLboolean Antialias = GL_FALSE;
18 static GLboolean Animate = GL_FALSE;
19 static GLint Texture = 1;
20 static GLboolean Stipple = GL_FALSE;
21 static GLfloat LineWidth = 1.0;
22
23 static GLfloat Xrot = -60.0, Yrot = 0.0, Zrot = 0.0;
24 static GLfloat DYrot = 1.0;
25 static GLboolean Points = GL_FALSE;
26 static GLfloat Scale = 1.0;
27
28 static void Idle( void )
29 {
30 if (Animate) {
31 Zrot += DYrot;
32 glutPostRedisplay();
33 }
34 }
35
36
37 static void Display( void )
38 {
39 GLfloat x, y, s, t;
40
41 glClear( GL_COLOR_BUFFER_BIT );
42
43 glPushMatrix();
44 glRotatef(Xrot, 1.0, 0.0, 0.0);
45 glRotatef(Yrot, 0.0, 1.0, 0.0);
46 glRotatef(Zrot, 0.0, 0.0, 1.0);
47 glScalef(Scale, Scale, Scale);
48
49 if (Texture)
50 glColor3f(1, 1, 1);
51
52 if (Points) {
53 glBegin(GL_POINTS);
54 for (t = 0.0; t <= 1.0; t += 0.025) {
55 for (s = 0.0; s <= 1.0; s += 0.025) {
56 x = s * 2.0 - 1.0;
57 y = t * 2.0 - 1.0;
58 if (!Texture)
59 glColor3f(1, 0, 1);
60 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t, s);
61 glTexCoord2f(s, t);
62 glVertex2f(x, y);
63 }
64 }
65 glEnd();
66 }
67 else {
68 glBegin(GL_LINES);
69 for (t = 0.0; t <= 1.0; t += 0.025) {
70 x = t * 2.0 - 1.0;
71 if (!Texture)
72 glColor3f(1, 0, 1);
73 glTexCoord2f(t, 0.0);
74 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, t);
75 glVertex2f(x, -1.0);
76 if (!Texture)
77 glColor3f(0, 1, 0);
78 glTexCoord2f(t, 1.0);
79 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, t);
80 glVertex2f(x, 1.0);
81 }
82 glEnd();
83 }
84
85 glPopMatrix();
86
87 glutSwapBuffers();
88 }
89
90
91 static void Reshape( int width, int height )
92 {
93 GLfloat ar = (float) width / height;
94 glViewport( 0, 0, width, height );
95 glMatrixMode( GL_PROJECTION );
96 glLoadIdentity();
97 glFrustum( -ar, ar, -1.0, 1.0, 10.0, 100.0 );
98 glMatrixMode( GL_MODELVIEW );
99 glLoadIdentity();
100 glTranslatef( 0.0, 0.0, -12.0 );
101 }
102
103
104 static void Key( unsigned char key, int x, int y )
105 {
106 (void) x;
107 (void) y;
108 switch (key) {
109 case 'a':
110 Antialias = !Antialias;
111 if (Antialias) {
112 glEnable(GL_LINE_SMOOTH);
113 glEnable(GL_POINT_SMOOTH);
114 glEnable(GL_BLEND);
115 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
116 }
117 else {
118 glDisable(GL_LINE_SMOOTH);
119 glDisable(GL_POINT_SMOOTH);
120 glDisable(GL_BLEND);
121 }
122 break;
123 case 't':
124 Texture++;
125 if (Texture > 2)
126 Texture = 0;
127 if (Texture == 0) {
128 glActiveTextureARB(GL_TEXTURE0_ARB);
129 glDisable(GL_TEXTURE_2D);
130 glActiveTextureARB(GL_TEXTURE1_ARB);
131 glDisable(GL_TEXTURE_2D);
132 }
133 else if (Texture == 1) {
134 glActiveTextureARB(GL_TEXTURE0_ARB);
135 glEnable(GL_TEXTURE_2D);
136 glActiveTextureARB(GL_TEXTURE1_ARB);
137 glDisable(GL_TEXTURE_2D);
138 }
139 else {
140 glActiveTextureARB(GL_TEXTURE0_ARB);
141 glEnable(GL_TEXTURE_2D);
142 glActiveTextureARB(GL_TEXTURE1_ARB);
143 glEnable(GL_TEXTURE_2D);
144 }
145 break;
146 case 'w':
147 LineWidth -= 0.25;
148 if (LineWidth < 0.25)
149 LineWidth = 0.25;
150 glLineWidth(LineWidth);
151 glPointSize(LineWidth);
152 break;
153 case 'W':
154 LineWidth += 0.25;
155 if (LineWidth > 8.0)
156 LineWidth = 8.0;
157 glLineWidth(LineWidth);
158 glPointSize(LineWidth);
159 break;
160 case 'p':
161 Points = !Points;
162 break;
163 case 's':
164 Stipple = !Stipple;
165 if (Stipple)
166 glEnable(GL_LINE_STIPPLE);
167 else
168 glDisable(GL_LINE_STIPPLE);
169 break;
170 case ' ':
171 Animate = !Animate;
172 if (Animate)
173 glutIdleFunc(Idle);
174 else
175 glutIdleFunc(NULL);
176 break;
177 case 27:
178 exit(0);
179 break;
180 }
181 printf("LineWidth, PointSize = %f\n", LineWidth);
182 glutPostRedisplay();
183 }
184
185
186 static void SpecialKey( int key, int x, int y )
187 {
188 float step = 3.0;
189 (void) x;
190 (void) y;
191
192 switch (key) {
193 case GLUT_KEY_UP:
194 Xrot += step;
195 break;
196 case GLUT_KEY_DOWN:
197 Xrot -= step;
198 break;
199 case GLUT_KEY_LEFT:
200 Yrot += step;
201 break;
202 case GLUT_KEY_RIGHT:
203 Yrot -= step;
204 break;
205 }
206 glutPostRedisplay();
207 }
208
209
210 static void Init( int argc, char *argv[] )
211 {
212 GLfloat r[2];
213 GLuint u;
214
215 for (u = 0; u < 2; u++) {
216 glActiveTextureARB(GL_TEXTURE0_ARB + u);
217 glBindTexture(GL_TEXTURE_2D, 10+u);
218 if (u == 0)
219 glEnable(GL_TEXTURE_2D);
220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
224
225 if (u == 0)
226 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
227 else
228 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
229
230 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
231 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
232 printf("Error: couldn't load texture image\n");
233 exit(1);
234 }
235 }
236
237 glLineStipple(1, 0xff);
238
239 if (argc > 1 && strcmp(argv[1], "-info")==0) {
240 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
241 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
242 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
243 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
244 }
245
246 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, r);
247 printf("Non-smooth point size range: %g .. %g\n", r[0], r[1]);
248 glGetFloatv(GL_POINT_SIZE_RANGE, r);
249 printf("Smoothed point size range: %g .. %g\n", r[0], r[1]);
250 glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, r);
251 printf("Non-smooth line width range: %g .. %g\n", r[0], r[1]);
252 glGetFloatv(GL_LINE_WIDTH_RANGE, r);
253 printf("Smoothed line width range: %g .. %g\n", r[0], r[1]);
254 }
255
256
257 int main( int argc, char *argv[] )
258 {
259 glutInit( &argc, argv );
260 glutInitWindowPosition(0, 0);
261 glutInitWindowSize( 400, 300 );
262
263 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
264
265 glutCreateWindow(argv[0] );
266
267 Init(argc, argv);
268
269 glutReshapeFunc( Reshape );
270 glutKeyboardFunc( Key );
271 glutSpecialFunc( SpecialKey );
272 glutDisplayFunc( Display );
273 if (Animate)
274 glutIdleFunc( Idle );
275
276 glutMainLoop();
277 return 0;
278 }