2 * Test NPOT textures with the GL_ARB_texture_non_power_of_two extension.
12 #include "glut_wrap.h"
13 #include "../util/readtex.c"
15 #define IMAGE_FILE DEMOS_DATA_DIR "girl.rgb"
17 static GLfloat Zrot
= 0;
19 static void Display( void )
21 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
24 glRotatef(Zrot
, 0, 0, 1);
41 static void Reshape( int width
, int height
)
43 glViewport( 0, 0, width
, height
);
44 glMatrixMode( GL_PROJECTION
);
46 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
47 glMatrixMode( GL_MODELVIEW
);
49 glTranslatef( 0.0, 0.0, -7.0 );
53 static void Key( unsigned char key
, int x
, int y
)
72 static void Init( void )
75 int imgWidth
, imgHeight
, minDim
, w
;
78 if (!glutExtensionSupported("GL_ARB_texture_non_power_of_two")) {
79 printf("Sorry, this program requires GL_ARB_texture_non_power_of_two\n");
84 image
= LoadRGBImage( IMAGE_FILE
, &imgWidth
, &imgHeight
, &imgFormat
);
86 printf("Couldn't read %s\n", IMAGE_FILE
);
94 image
= malloc(imgWidth
* imgHeight
* 3);
95 for (i
= 0; i
< imgHeight
; i
++) {
96 for (j
= 0; j
< imgWidth
; j
++) {
97 int k
= (i
* imgWidth
+ j
) * 3;
112 printf("Read %d x %d\n", imgWidth
, imgHeight
);
114 minDim
= imgWidth
< imgHeight
? imgWidth
: imgHeight
;
116 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
119 * 1D Texture. Test proxy first, if that works, test non-proxy target.
121 glTexImage1D(GL_PROXY_TEXTURE_1D
, 0, GL_RGB
, imgWidth
, 0,
122 imgFormat
, GL_UNSIGNED_BYTE
, image
);
123 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_1D
, 0, GL_TEXTURE_WIDTH
, &w
);
124 assert(w
== imgWidth
|| w
== 0);
127 glTexImage1D(GL_TEXTURE_1D
, 0, GL_RGB
, imgWidth
, 0,
128 imgFormat
, GL_UNSIGNED_BYTE
, image
);
129 assert(glGetError() == GL_NO_ERROR
);
136 glTexImage2D(GL_PROXY_TEXTURE_2D
, 0, GL_RGB
, imgWidth
, imgHeight
, 0,
137 imgFormat
, GL_UNSIGNED_BYTE
, image
);
138 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D
, 0, GL_TEXTURE_WIDTH
, &w
);
139 assert(w
== imgWidth
|| w
== 0);
142 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, imgWidth
, imgHeight
, 0,
143 imgFormat
, GL_UNSIGNED_BYTE
, image
);
144 assert(glGetError() == GL_NO_ERROR
);
151 glTexImage3D(GL_PROXY_TEXTURE_3D
, 0, GL_RGB
, imgWidth
, imgHeight
, 1, 0,
152 imgFormat
, GL_UNSIGNED_BYTE
, image
);
153 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D
, 0, GL_TEXTURE_WIDTH
, &w
);
154 assert(w
== imgWidth
|| w
== 0);
157 glTexImage3D(GL_TEXTURE_3D
, 0, GL_RGB
, imgWidth
, imgHeight
, 1, 0,
158 imgFormat
, GL_UNSIGNED_BYTE
, image
);
159 assert(glGetError() == GL_NO_ERROR
);
166 glTexImage2D(GL_PROXY_TEXTURE_CUBE_MAP
, 0, GL_RGB
,
168 imgFormat
, GL_UNSIGNED_BYTE
, image
);
169 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_CUBE_MAP
, 0, GL_TEXTURE_WIDTH
, &w
);
170 assert(w
== minDim
|| w
== 0);
173 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0, GL_RGB
,
175 imgFormat
, GL_UNSIGNED_BYTE
, image
);
176 assert(glGetError() == GL_NO_ERROR
);
179 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
180 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
181 glEnable(GL_TEXTURE_2D
);
185 int main( int argc
, char *argv
[] )
187 glutInit( &argc
, argv
);
188 glutInitWindowPosition( 0, 0 );
189 glutInitWindowSize( 400, 400 );
190 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
191 glutCreateWindow(argv
[0]);
193 glutReshapeFunc( Reshape
);
194 glutKeyboardFunc( Key
);
195 glutDisplayFunc( Display
);