2 * Test texture compression.
13 #include "texcomp_image.h"
15 static int ImgWidth
= 512;
16 static int ImgHeight
= 512;
17 static GLenum CompFormat
= GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
;
18 static GLfloat EyeDist
= 5.0;
19 static GLfloat Rot
= 0.0;
20 const GLenum Target
= GL_TEXTURE_2D
;
26 GLenum err
= glGetError();
28 printf("GL Error %d at line %d\n", (int) err
, line
);
33 LoadCompressedImage(void)
35 unsigned char ImgDataTemp
[ImgSize
/ 4];
37 const GLenum filter
= GL_LINEAR
;
38 const int half
= ImgSize
/ 2;
40 glTexImage2D(Target
, 0, CompFormat
, ImgWidth
, ImgHeight
, 0,
41 GL_RGB
, GL_UNSIGNED_BYTE
, NULL
);
44 glCompressedTexSubImage2DARB(Target
, 0,
46 ImgWidth
, ImgHeight
/ 2,
47 CompFormat
, ImgSize
/ 2, ImgData
/*+ ImgSize / 2*/);
50 for (i
= 0; i
< ImgHeight
/ 8; i
++) {
51 memcpy(&ImgDataTemp
[i
* ImgWidth
], &ImgData
[half
+ i
* 2 * ImgWidth
], ImgWidth
);
53 glCompressedTexSubImage2DARB(Target
, 0,
54 0, ImgHeight
/ 2, /* pos */
55 ImgWidth
/ 2, ImgHeight
/ 2,
56 CompFormat
, ImgSize
/ 4, ImgDataTemp
);
59 for (i
= 0; i
< ImgHeight
/ 8; i
++) {
60 memcpy(&ImgDataTemp
[i
* ImgWidth
], &ImgData
[half
+ i
* 2 * ImgWidth
+ ImgWidth
], ImgWidth
);
62 glCompressedTexSubImage2DARB(Target
, 0,
63 ImgWidth
/ 2, ImgHeight
/ 2, /* pos */
64 ImgWidth
/ 2, ImgHeight
/ 2,
65 CompFormat
, ImgSize
/ 4, ImgDataTemp
);
67 glTexParameteri(Target
, GL_TEXTURE_MIN_FILTER
, filter
);
68 glTexParameteri(Target
, GL_TEXTURE_MAG_FILTER
, filter
);
74 GLint numFormats
, formats
[100];
77 if (!glutExtensionSupported("GL_ARB_texture_compression")) {
78 printf("Sorry, GL_ARB_texture_compression is required.\n");
81 if (!glutExtensionSupported("GL_EXT_texture_compression_s3tc")) {
82 printf("Sorry, GL_EXT_texture_compression_s3tc is required.\n");
86 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
87 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
89 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
, &numFormats
);
90 glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS_ARB
, formats
);
91 printf("%d supported compression formats: ", numFormats
);
92 for (p
= 0; p
< numFormats
; p
++)
93 printf("0x%x ", formats
[p
]);
96 glEnable(GL_TEXTURE_2D
);
98 LoadCompressedImage();
103 Reshape( int width
, int height
)
105 glViewport( 0, 0, width
, height
);
106 glMatrixMode( GL_PROJECTION
);
108 glFrustum(-1, 1, -1, 1, 4, 100);
109 glMatrixMode( GL_MODELVIEW
);
115 Key( unsigned char key
, int x
, int y
)
145 glClearColor(0.3, 0.3, .8, 0);
146 glClear(GL_COLOR_BUFFER_BIT
);
148 CheckError(__LINE__
);
150 glTranslatef(0, 0, -(EyeDist
+0.01));
151 glRotatef(Rot
, 0, 0, 1);
153 glTexCoord2f(0, 0); glVertex2f(-1, -1);
154 glTexCoord2f(1, 0); glVertex2f( 1, -1);
155 glTexCoord2f(1, 1); glVertex2f( 1, 1);
156 glTexCoord2f(0, 1); glVertex2f(-1, 1);
165 main( int argc
, char *argv
[] )
167 glutInit( &argc
, argv
);
168 glutInitWindowSize( 600, 600 );
170 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
172 glutCreateWindow(argv
[0]);
175 glutReshapeFunc( Reshape
);
176 glutKeyboardFunc( Key
);
177 glutDisplayFunc( Draw
);