blob: 773da3c1aa63c949276a9897b681220b87901fbc [file] [log] [blame]
Brian Paul6140a8c2001-01-23 23:44:39 +00001/* $Id: texline.c,v 1.2 2001/01/23 23:44:39 brianp Exp $ */
Brian Paul22f1ca02000-09-30 18:48:33 +00002
3/*
4 * Test textured lines.
5 *
6 * Brian Paul
7 * September 2000
8 */
9
10
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. */
16
17#define TEXTURE_FILE "../images/girl.rgb"
18
19static GLboolean Antialias = GL_FALSE;
20static GLboolean Animate = GL_TRUE;
21static GLboolean Texture = GL_TRUE;
22static GLfloat LineWidth = 1.0;
23
24static GLfloat Xrot = -60.0, Yrot = 0.0, Zrot = 0.0;
25static GLfloat DYrot = 1.0;
26
27
28static void Idle( void )
29{
30 if (Animate) {
31 Zrot += DYrot;
32 glutPostRedisplay();
33 }
34}
35
36
37static void Display( void )
38{
39 GLfloat x, 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
Brian Paul6140a8c2001-01-23 23:44:39 +000048 if (Texture)
49 glColor3f(1, 1, 1);
50
Brian Paul22f1ca02000-09-30 18:48:33 +000051 glBegin(GL_LINES);
Brian Paul6140a8c2001-01-23 23:44:39 +000052 for (t = 0.0; t <= 1.0; t += 0.025) {
Brian Paul22f1ca02000-09-30 18:48:33 +000053 x = t * 2.0 - 1.0;
Brian Paul6140a8c2001-01-23 23:44:39 +000054 if (!Texture)
55 glColor3f(1, 0, 1);
Brian Paul22f1ca02000-09-30 18:48:33 +000056 glTexCoord2f(t, 0.0); glVertex2f(x, -1.0);
Brian Paul6140a8c2001-01-23 23:44:39 +000057 if (!Texture)
58 glColor3f(0, 1, 0);
Brian Paul22f1ca02000-09-30 18:48:33 +000059 glTexCoord2f(t, 1.0); glVertex2f(x, 1.0);
60 }
61 glEnd();
62
63 glPopMatrix();
64
65 glutSwapBuffers();
66}
67
68
69static void Reshape( int width, int height )
70{
71 GLfloat ar = (float) width / height;
72 glViewport( 0, 0, width, height );
73 glMatrixMode( GL_PROJECTION );
74 glLoadIdentity();
75 glFrustum( -ar, ar, -1.0, 1.0, 10.0, 100.0 );
76 glMatrixMode( GL_MODELVIEW );
77 glLoadIdentity();
78 glTranslatef( 0.0, 0.0, -12.0 );
79}
80
81
82static void Key( unsigned char key, int x, int y )
83{
84 (void) x;
85 (void) y;
86 switch (key) {
87 case 'a':
88 Antialias = !Antialias;
89 if (Antialias) {
90 glEnable(GL_LINE_SMOOTH);
91 glEnable(GL_BLEND);
92 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
93 }
94 else {
95 glDisable(GL_LINE_SMOOTH);
96 glDisable(GL_BLEND);
97 }
98 break;
99 case 't':
100 Texture = !Texture;
101 if (Texture)
102 glEnable(GL_TEXTURE_2D);
103 else
104 glDisable(GL_TEXTURE_2D);
105 break;
106 case 'w':
107 LineWidth -= 0.25;
108 if (LineWidth < 0.25)
109 LineWidth = 0.25;
110 glLineWidth(LineWidth);
111 break;
112 case 'W':
113 LineWidth += 0.25;
114 if (LineWidth > 8.0)
115 LineWidth = 8.0;
116 glLineWidth(LineWidth);
117 break;
118 case ' ':
119 Animate = !Animate;
120 if (Animate)
121 glutIdleFunc(Idle);
122 else
123 glutIdleFunc(NULL);
124 break;
125 case 27:
126 exit(0);
127 break;
128 }
129 printf("Width %f\n", LineWidth);
130 glutPostRedisplay();
131}
132
133
134static void SpecialKey( int key, int x, int y )
135{
136 float step = 3.0;
137 (void) x;
138 (void) y;
139
140 switch (key) {
141 case GLUT_KEY_UP:
142 Xrot += step;
143 break;
144 case GLUT_KEY_DOWN:
145 Xrot -= step;
146 break;
147 case GLUT_KEY_LEFT:
148 Yrot += step;
149 break;
150 case GLUT_KEY_RIGHT:
151 Yrot -= step;
152 break;
153 }
154 glutPostRedisplay();
155}
156
157
158static void Init( int argc, char *argv[] )
159{
160 glEnable(GL_TEXTURE_2D);
161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
165
166 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
167
168 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
169 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
170 printf("Error: couldn't load texture image\n");
171 exit(1);
172 }
173
174 if (argc > 1 && strcmp(argv[1], "-info")==0) {
175 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
176 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
177 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
178 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
179 }
180}
181
182
183int main( int argc, char *argv[] )
184{
185 glutInit( &argc, argv );
186 glutInitWindowSize( 400, 300 );
187
188 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
189
190 glutCreateWindow(argv[0] );
191
192 Init(argc, argv);
193
194 glutReshapeFunc( Reshape );
195 glutKeyboardFunc( Key );
196 glutSpecialFunc( SpecialKey );
197 glutDisplayFunc( Display );
198 glutIdleFunc( Idle );
199
200 glutMainLoop();
201 return 0;
202}