Import sarea.h from Xorg, needed for client GLX code.
[mesa-demos.git] / src / miniglx / texline.c
blobd2a97d2876ea2ad3ddf80aec907e2f93d71ec5f5
1 /* $Id: texline.c,v 1.1 2003/08/06 17:47:15 keithw Exp $ */
3 /*
4 * Test textured lines.
6 * Brian Paul
7 * September 2000
8 */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <math.h>
14 #include <GL/glut.h>
15 #include "../util/readtex.c" /* I know, this is a hack. */
17 #define TEXTURE_FILE "../images/girl.rgb"
19 static GLboolean Antialias = GL_FALSE;
20 static GLboolean Animate = GL_FALSE;
21 static GLint Texture = 1;
22 static GLboolean Stipple = GL_FALSE;
23 static GLfloat LineWidth = 1.0;
25 static GLfloat Xrot = -60.0, Yrot = 0.0, Zrot = 0.0;
26 static GLfloat DYrot = 1.0;
27 static GLboolean Points = GL_FALSE;
28 static GLfloat Scale = 1.0;
30 static void Idle( void )
32 if (Animate) {
33 Zrot += DYrot;
34 glutPostRedisplay();
39 static void Display( void )
41 GLfloat x, y, s, t;
43 glClear( GL_COLOR_BUFFER_BIT );
45 glPushMatrix();
46 glRotatef(Xrot, 1.0, 0.0, 0.0);
47 glRotatef(Yrot, 0.0, 1.0, 0.0);
48 glRotatef(Zrot, 0.0, 0.0, 1.0);
49 glScalef(Scale, Scale, Scale);
51 if (Texture)
52 glColor3f(1, 1, 1);
54 if (Points) {
55 glBegin(GL_POINTS);
56 for (t = 0.0; t <= 1.0; t += 0.025) {
57 for (s = 0.0; s <= 1.0; s += 0.025) {
58 x = s * 2.0 - 1.0;
59 y = t * 2.0 - 1.0;
60 if (!Texture)
61 glColor3f(1, 0, 1);
62 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t, s);
63 glTexCoord2f(s, t);
64 glVertex2f(x, y);
67 glEnd();
69 else {
70 glBegin(GL_LINES);
71 for (t = 0.0; t <= 1.0; t += 0.025) {
72 x = t * 2.0 - 1.0;
73 if (!Texture)
74 glColor3f(1, 0, 1);
75 glTexCoord2f(t, 0.0);
76 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, t);
77 glVertex2f(x, -1.0);
78 if (!Texture)
79 glColor3f(0, 1, 0);
80 glTexCoord2f(t, 1.0);
81 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, t);
82 glVertex2f(x, 1.0);
84 glEnd();
87 glPopMatrix();
89 glutSwapBuffers();
93 static void Reshape( int width, int height )
95 GLfloat ar = (float) width / height;
96 glViewport( 0, 0, width, height );
97 glMatrixMode( GL_PROJECTION );
98 glLoadIdentity();
99 glFrustum( -ar, ar, -1.0, 1.0, 10.0, 100.0 );
100 glMatrixMode( GL_MODELVIEW );
101 glLoadIdentity();
102 glTranslatef( 0.0, 0.0, -12.0 );
106 static void Key( unsigned char key, int x, int y )
108 (void) x;
109 (void) y;
110 switch (key) {
111 case 'a':
112 Antialias = !Antialias;
113 if (Antialias) {
114 glEnable(GL_LINE_SMOOTH);
115 glEnable(GL_POINT_SMOOTH);
116 glEnable(GL_BLEND);
117 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
119 else {
120 glDisable(GL_LINE_SMOOTH);
121 glDisable(GL_POINT_SMOOTH);
122 glDisable(GL_BLEND);
124 break;
125 case 't':
126 Texture++;
127 if (Texture > 2)
128 Texture = 0;
129 if (Texture == 0) {
130 glActiveTextureARB(GL_TEXTURE0_ARB);
131 glDisable(GL_TEXTURE_2D);
132 glActiveTextureARB(GL_TEXTURE1_ARB);
133 glDisable(GL_TEXTURE_2D);
135 else if (Texture == 1) {
136 glActiveTextureARB(GL_TEXTURE0_ARB);
137 glEnable(GL_TEXTURE_2D);
138 glActiveTextureARB(GL_TEXTURE1_ARB);
139 glDisable(GL_TEXTURE_2D);
141 else {
142 glActiveTextureARB(GL_TEXTURE0_ARB);
143 glEnable(GL_TEXTURE_2D);
144 glActiveTextureARB(GL_TEXTURE1_ARB);
145 glEnable(GL_TEXTURE_2D);
147 break;
148 case 'w':
149 LineWidth -= 0.25;
150 if (LineWidth < 0.25)
151 LineWidth = 0.25;
152 glLineWidth(LineWidth);
153 glPointSize(LineWidth);
154 break;
155 case 'W':
156 LineWidth += 0.25;
157 if (LineWidth > 8.0)
158 LineWidth = 8.0;
159 glLineWidth(LineWidth);
160 glPointSize(LineWidth);
161 break;
162 case 'p':
163 Points = !Points;
164 break;
165 case 's':
166 Stipple = !Stipple;
167 if (Stipple)
168 glEnable(GL_LINE_STIPPLE);
169 else
170 glDisable(GL_LINE_STIPPLE);
171 break;
172 case ' ':
173 Animate = !Animate;
174 if (Animate)
175 glutIdleFunc(Idle);
176 else
177 glutIdleFunc(NULL);
178 break;
179 case 27:
180 exit(0);
181 break;
183 printf("LineWidth, PointSize = %f\n", LineWidth);
184 glutPostRedisplay();
188 static void SpecialKey( int key, int x, int y )
190 float step = 3.0;
191 (void) x;
192 (void) y;
194 switch (key) {
195 case GLUT_KEY_UP:
196 Xrot += step;
197 break;
198 case GLUT_KEY_DOWN:
199 Xrot -= step;
200 break;
201 case GLUT_KEY_LEFT:
202 Yrot += step;
203 break;
204 case GLUT_KEY_RIGHT:
205 Yrot -= step;
206 break;
208 glutPostRedisplay();
212 static void Init( int argc, char *argv[] )
214 GLuint u;
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);
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);
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);
237 glLineStipple(1, 0xff);
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));
248 int main( int argc, char *argv[] )
250 glutInit( &argc, argv );
251 glutInitWindowSize( 400, 300 );
253 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
255 glutCreateWindow(argv[0] );
257 Init(argc, argv);
259 glutReshapeFunc( Reshape );
260 glutKeyboardFunc( Key );
261 glutSpecialFunc( SpecialKey );
262 glutDisplayFunc( Display );
263 if (Animate)
264 glutIdleFunc( Idle );
266 glutMainLoop();
267 return 0;