~ubuntu-branches/ubuntu/jaunty/mesa/jaunty

« back to all changes in this revision

Viewing changes to progs/miniglx/texline.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-01-23 10:20:24 UTC
  • mfrom: (1.2.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20090123102024-1f3kmb3aea7wzk67
Tags: 7.3~rc3-1ubuntu1
* Merge with Debian experimental.
* Drop 102_dont_vblank.patch, since the new drm code in the kernel
  fixes the bugs that it worked around.
* Bump the build-dependency of libdrm to 2.4.4. It's the first version
  with necessary changes to build this.

Show diffs side-by-side

added added

removed removed

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