#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 static GLfloat colorTable[][3] = { { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, 0.0, 1.0}, { 1.0, 1.0, 1.0}, { 1.0, 1.0, 0.0}, { 1.0, 0.0, 1.0}, { 0.0, 1.0, 1.0} }; #define TEXTURE_SIZE 64 void MakeMipmap (void) { GLfloat buf[TEXTURE_SIZE * TEXTURE_SIZE * 3]; GLint i, j, level, size; GLfloat *ptr; level = 0; for (size = TEXTURE_SIZE; size > 0; size /= 2) { ptr = buf; for (i = 0; i < size; i++) for (j = 0; j < size; j++) { *ptr++ = colorTable[level + 1][0]; *ptr++ = colorTable[level + 1][1]; *ptr++ = colorTable[level + 1][2]; } glTexImage2D (GL_TEXTURE_2D, level, 3, size, size, 0, GL_RGB, GL_FLOAT, buf); level++; } } void init (void) { int i; GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; glClearColor (0.0, 0.0, 0.0, 1.0); glColor4fv (white); glDisable (GL_DITHER); } static void test (void) { int i, j; GLuint texName; GLfloat maxLodBias; glClear (GL_COLOR_BUFFER_BIT); glGenTextures (1, &texName); glBindTexture (GL_TEXTURE_1D, texName); MakeMipmap (); glBindTexture (GL_TEXTURE_1D, texName); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 5); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glEnable (GL_TEXTURE_2D); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glClear (GL_COLOR_BUFFER_BIT); glBegin (GL_POLYGON); glTexCoord2f (0.0, 0.0); glVertex2i (0, 0); glTexCoord2f (0.0, 1.0); glVertex2i (0, TEXTURE_SIZE); glTexCoord2f (1.0, 1.0); glVertex2i (TEXTURE_SIZE, TEXTURE_SIZE); glTexCoord2f (1.0, 0.0); glVertex2i (TEXTURE_SIZE, 0); glEnd (); glFlush (); } void display (void) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, WINDSIZEX, 0, WINDSIZEX); test (); } int main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize (WINDSIZEX, WINDSIZEY); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc (display); glutMainLoop (); return 0; }