/* * Test mipmap generation and lod bias. * * Brian Paul * 17 March 2008 */ #include #include #include #include #include #include #include #include "readtex.h" #define TEXTURE_FILE "../images/arch.rgb" #define LEVELS 8 #define SIZE (1< 0) { if (texWidth == 1 && texHeight == 1) break; texWidth = TexWidth >> bias; texHeight = TexHeight >> bias; if (texWidth < 1) texWidth = 1; if (texHeight < 1) texHeight = 1; } glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.0); } else { glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, bias); } glRasterPos2f(x, y + TexHeight + 5); if (ScaleQuads) sprintf(str, "Texture Level %d: %d x %d", (bias < 0 ? 0 : bias), texWidth, texHeight); else sprintf(str, "Texture LOD Bias = %d", bias); PrintString(str); glPushMatrix(); glTranslatef(x, y, 0); glEnable(GL_TEXTURE_2D); glBegin(GL_POLYGON); glTexCoord2f(0, 0); glVertex2f(0, 0); glTexCoord2f(1, 0); glVertex2f(texWidth, 0); glTexCoord2f(1, 1); glVertex2f(texWidth, texHeight); glTexCoord2f(0, 1); glVertex2f(0, texHeight); glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); x += TexWidth + 4; if (x >= WinWidth) { x = 4; y -= 300; } } glutSwapBuffers(); } static void Reshape(int width, int height) { WinWidth = width; WinHeight = height; } static void Key(unsigned char key, int x, int y) { (void) x; (void) y; switch (key) { case 'b': Bias -= 10; break; case 'B': Bias += 10; break; case 'l': Linear = !Linear; break; case 'v': RenderTextureLevel++; break; case 'V': RenderTextureLevel--; break; case 'r': RenderTexture(); break; case 'X': ResetTexture(); break; case 'x': ResetTextureLevel(RenderTextureLevel); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': Bias = 100.0 * (key - '0'); break; case 's': ScaleQuads = !ScaleQuads; break; case ' ': MipGenTexture(); Bias = 0; Linear = 0; RenderTextureLevel = 0; ScaleQuads = 0; break; case 27: glutDestroyWindow(Win); exit(0); break; } glutPostRedisplay(); } static void Init(void) { GLfloat maxBias; if (!glutExtensionSupported("GL_EXT_texture_lod_bias")) { printf("Sorry, GL_EXT_texture_lod_bias not supported by this renderer.\n"); exit(1); } if (!glutExtensionSupported("GL_SGIS_generate_mipmap")) { printf("Sorry, GL_SGIS_generate_mipmap not supported by this renderer.\n"); exit(1); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TexObj); glBindTexture(GL_TEXTURE_2D, TexObj); if (1) MipGenTexture(); else ResetTexture(); /* mipmapping required for this extension */ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &maxBias); printf("GL_RENDERER: %s\n", (char*) glGetString(GL_RENDERER)); printf("LOD bias range: [%g, %g]\n", -maxBias, maxBias); printf("Press 's' to toggle quad scaling\n"); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowPosition(0, 0); glutInitWindowSize(WinWidth, WinHeight); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); Init(); glutMainLoop(); return 0; }