diff options
author | Brian Paul <[email protected]> | 2002-12-10 16:51:28 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2002-12-10 16:51:28 +0000 |
commit | 76d2a77291eb323c138751c0c605d120efe6cb38 (patch) | |
tree | 88be4d376408bc02af1ff7153a728bf4249a1814 /progs/demos/lodbias.c | |
parent | 6f458650bf27fc7a86e90338cf583bd44fc630c2 (diff) |
use/test GL_SGIS_generate_mipmaps if available
Diffstat (limited to 'progs/demos/lodbias.c')
-rw-r--r-- | progs/demos/lodbias.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/progs/demos/lodbias.c b/progs/demos/lodbias.c index 3533241be55..bee06da80b0 100644 --- a/progs/demos/lodbias.c +++ b/progs/demos/lodbias.c @@ -27,6 +27,7 @@ */ +#include <assert.h> #include <stdlib.h> #include <stdio.h> #include <math.h> @@ -191,16 +192,53 @@ static void SpecialKey( int key, int x, int y ) static void Init( void ) { - const char *exten = (const char *) glGetString(GL_EXTENSIONS); GLfloat maxBias; - if (!strstr(exten, "GL_EXT_texture_lod_bias")) { + if (!glutExtensionSupported("GL_EXT_texture_lod_bias")) { printf("Sorry, GL_EXT_texture_lod_bias not supported by this renderer.\n"); exit(1); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + + if (glutExtensionSupported("GL_SGIS_generate_mipmap")) { + /* test auto mipmap generation */ + GLint width, height, i; + GLenum format; + GLubyte *image = LoadRGBImage(TEXTURE_FILE, &width, &height, &format); + if (!image) { + printf("Error: could not load texture image %s\n", TEXTURE_FILE); + exit(1); + } + /* resize to 256 x 256 */ + if (width != 256 || height != 256) { + GLubyte *newImage = malloc(256 * 256 * 4); + gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, + 256, 256, GL_UNSIGNED_BYTE, newImage); + free(image); + image = newImage; + } + printf("Using GL_SGIS_generate_mipmap\n"); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, format, 256, 256, 0, + format, GL_UNSIGNED_BYTE, image); + free(image); + + /* make sure mipmap was really generated correctly */ + width = height = 256; + for (i = 0; i < 9; i++) { + GLint w, h; + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); + printf("Level %d size: %d x %d\n", i, w, h); + assert(w == width); + assert(h == height); + width /= 2; + height /= 2; + } + + } + else if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { printf("Error: could not load texture image %s\n", TEXTURE_FILE); exit(1); } |