2
* Test NPOT textures with the GL_ARB_texture_non_power_of_two extension.
12
#include "../util/readtex.c"
14
#define IMAGE_FILE "../images/girl.rgb"
16
static GLfloat Zrot = 0;
18
static void Display( void )
20
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
23
glRotatef(Zrot, 0, 0, 1);
40
static void Reshape( int width, int height )
42
glViewport( 0, 0, width, height );
43
glMatrixMode( GL_PROJECTION );
45
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
46
glMatrixMode( GL_MODELVIEW );
48
glTranslatef( 0.0, 0.0, -7.0 );
52
static void Key( unsigned char key, int x, int y )
71
static void Init( void )
74
int imgWidth, imgHeight, minDim, w;
77
if (!glutExtensionSupported("GL_ARB_texture_non_power_of_two")) {
78
printf("Sorry, this program requires GL_ARB_texture_non_power_of_two\n");
83
image = LoadRGBImage( IMAGE_FILE, &imgWidth, &imgHeight, &imgFormat );
85
printf("Couldn't read %s\n", IMAGE_FILE);
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;
111
printf("Read %d x %d\n", imgWidth, imgHeight);
113
minDim = imgWidth < imgHeight ? imgWidth : imgHeight;
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);
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);
125
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0,
126
imgFormat, GL_UNSIGNED_BYTE, image);
127
assert(glGetError() == GL_NO_ERROR);
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);
134
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, imgWidth, imgHeight, 1, 0,
135
imgFormat, GL_UNSIGNED_BYTE, image);
136
assert(glGetError() == GL_NO_ERROR);
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);
143
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB,
145
imgFormat, GL_UNSIGNED_BYTE, image);
146
assert(glGetError() == GL_NO_ERROR);
148
glTexImage2D(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_RGB,
150
imgFormat, GL_UNSIGNED_BYTE, image);
151
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_TEXTURE_WIDTH, &w);
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);
161
int main( int argc, char *argv[] )
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 );