~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to progs/tests/arbnpot.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Test NPOT textures with the GL_ARB_texture_non_power_of_two extension.
3
 
 * Brian Paul
4
 
 * 2 July 2003
5
 
 */
6
 
 
7
 
#include <assert.h>
8
 
#include <stdio.h>
9
 
#include <stdlib.h>
10
 
#include <math.h>
11
 
#include <GL/glut.h>
12
 
#include "../util/readtex.c"
13
 
 
14
 
#define IMAGE_FILE "../images/girl.rgb"
15
 
 
16
 
static GLfloat Zrot = 0;
17
 
 
18
 
static void Display( void )
19
 
{
20
 
   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
21
 
 
22
 
   glPushMatrix();
23
 
   glRotatef(Zrot, 0, 0, 1);
24
 
   glBegin(GL_POLYGON);
25
 
   glTexCoord2f(0, 0);
26
 
   glVertex2f(-1, -1);
27
 
   glTexCoord2f(1, 0);
28
 
   glVertex2f(1, -1);
29
 
   glTexCoord2f(1, 1);
30
 
   glVertex2f(1, 1);
31
 
   glTexCoord2f(0, 1);
32
 
   glVertex2f(-1, 1);
33
 
   glEnd();
34
 
   glPopMatrix();
35
 
 
36
 
   glutSwapBuffers();
37
 
}
38
 
 
39
 
 
40
 
static void Reshape( int width, int height )
41
 
{
42
 
   glViewport( 0, 0, width, height );
43
 
   glMatrixMode( GL_PROJECTION );
44
 
   glLoadIdentity();
45
 
   glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
46
 
   glMatrixMode( GL_MODELVIEW );
47
 
   glLoadIdentity();
48
 
   glTranslatef( 0.0, 0.0, -7.0 );
49
 
}
50
 
 
51
 
 
52
 
static void Key( unsigned char key, int x, int y )
53
 
{
54
 
   (void) x;
55
 
   (void) y;
56
 
   switch (key) {
57
 
      case 'z':
58
 
         Zrot -= 1.0;
59
 
         break;
60
 
      case 'Z':
61
 
         Zrot += 1.0;
62
 
         break;
63
 
      case 27:
64
 
         exit(0);
65
 
         break;
66
 
   }
67
 
   glutPostRedisplay();
68
 
}
69
 
 
70
 
 
71
 
static void Init( void )
72
 
{
73
 
   GLubyte *image;
74
 
   int imgWidth, imgHeight, minDim, w;
75
 
   GLenum imgFormat;
76
 
 
77
 
   if (!glutExtensionSupported("GL_ARB_texture_non_power_of_two")) {
78
 
      printf("Sorry, this program requires GL_ARB_texture_non_power_of_two\n");
79
 
      exit(1);
80
 
   }
81
 
 
82
 
#if 1
83
 
   image = LoadRGBImage( IMAGE_FILE, &imgWidth, &imgHeight, &imgFormat );
84
 
   if (!image) {
85
 
      printf("Couldn't read %s\n", IMAGE_FILE);
86
 
      exit(0);
87
 
   }
88
 
#else
89
 
   int i, j;
90
 
   imgFormat = GL_RGB;
91
 
   imgWidth = 3;
92
 
   imgHeight = 3;
93
 
   image = malloc(imgWidth * imgHeight * 3);
94
 
   for (i = 0; i < imgHeight; i++) {
95
 
      for (j = 0; j < imgWidth; j++) {
96
 
         int k = (i * imgWidth + j) * 3;
97
 
         if ((i + j) & 1) {
98
 
            image[k+0] = 255;
99
 
            image[k+1] = 0;
100
 
            image[k+2] = 0;
101
 
         }
102
 
         else {
103
 
            image[k+0] = 0;
104
 
            image[k+1] = 255;
105
 
            image[k+2] = 0;
106
 
         }
107
 
      }
108
 
   }
109
 
#endif
110
 
 
111
 
   printf("Read %d x %d\n", imgWidth, imgHeight);
112
 
 
113
 
   minDim = imgWidth < imgHeight ? imgWidth : imgHeight;
114
 
 
115
 
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
116
 
   glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, imgWidth, 0,
117
 
                imgFormat, GL_UNSIGNED_BYTE, image);
118
 
   assert(glGetError() == GL_NO_ERROR);
119
 
 
120
 
   glTexImage1D(GL_PROXY_TEXTURE_1D, 0, GL_RGB, imgWidth, 0,
121
 
                imgFormat, GL_UNSIGNED_BYTE, image);
122
 
   glGetTexLevelParameteriv(GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_WIDTH, &w);
123
 
   assert(w == imgWidth);
124
 
 
125
 
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0,
126
 
                imgFormat, GL_UNSIGNED_BYTE, image);
127
 
   assert(glGetError() == GL_NO_ERROR);
128
 
 
129
 
   glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0,
130
 
                imgFormat, GL_UNSIGNED_BYTE, image);
131
 
   glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
132
 
   assert(w == imgWidth);
133
 
 
134
 
   glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, imgWidth, imgHeight, 1, 0,
135
 
                imgFormat, GL_UNSIGNED_BYTE, image);
136
 
   assert(glGetError() == GL_NO_ERROR);
137
 
 
138
 
   glTexImage3D(GL_PROXY_TEXTURE_3D, 0, GL_RGB, imgWidth, imgHeight, 1, 0,
139
 
                imgFormat, GL_UNSIGNED_BYTE, image);
140
 
   glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &w);
141
 
   assert(w == imgWidth);
142
 
 
143
 
   glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB,
144
 
                minDim, minDim, 0,
145
 
                imgFormat, GL_UNSIGNED_BYTE, image);
146
 
   assert(glGetError() == GL_NO_ERROR);
147
 
 
148
 
   glTexImage2D(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_RGB,
149
 
                minDim, minDim, 0,
150
 
                imgFormat, GL_UNSIGNED_BYTE, image);
151
 
   glGetTexLevelParameteriv(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_TEXTURE_WIDTH, &w);
152
 
   assert(w == minDim);
153
 
 
154
 
 
155
 
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
156
 
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
157
 
   glEnable(GL_TEXTURE_2D);
158
 
}
159
 
 
160
 
 
161
 
int main( int argc, char *argv[] )
162
 
{
163
 
   glutInit( &argc, argv );
164
 
   glutInitWindowPosition( 0, 0 );
165
 
   glutInitWindowSize( 400, 400 );
166
 
   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
167
 
   glutCreateWindow(argv[0]);
168
 
   glutReshapeFunc( Reshape );
169
 
   glutKeyboardFunc( Key );
170
 
   glutDisplayFunc( Display );
171
 
   Init();
172
 
   glutMainLoop();
173
 
   return 0;
174
 
}