#include "GL/glut.h" #include #include #include #include #define WIN_WIDTH 128 #define WIN_HEIGHT 128 #define SQUARE_SIDE 64 #define MY_MIN_LOD 100 GLfloat mipmapImage64[64][64][3]; GLfloat mipmapImage32[32][32][3]; GLfloat mipmapImage16[16][16][3]; GLfloat mipmapImage8[8][8][3]; GLfloat mipmapImage4[4][4][3]; GLfloat mipmapImage2[2][2][3]; GLfloat mipmapImage1[1][1][3]; GLfloat buf[64*64*3]; void makeImages(void) { int i, j; for (i = 0; i < 64; i++) { for (j = 0; j < 64; j++) { mipmapImage64[i][j][0] = 0.64; mipmapImage64[i][j][1] = 0.0; mipmapImage64[i][j][2] = 0.0; } } for (i = 0; i < 32; i++) { for (j = 0; j < 32; j++) { mipmapImage32[i][j][0] = 0.32; mipmapImage32[i][j][1] = 0.0; mipmapImage32[i][j][2] = 0.0; } } for (i = 0; i < 16; i++) { for (j = 0; j < 16; j++) { mipmapImage16[i][j][0] = 0.16; mipmapImage16[i][j][1] = 0.0; mipmapImage16[i][j][2] = 0.0; } } for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { mipmapImage8[i][j][0] = 0.8; mipmapImage8[i][j][1] = 0.0; mipmapImage8[i][j][2] = 0.0; } } for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { mipmapImage4[i][j][0] = 0.4; mipmapImage4[i][j][1] = 0.0; mipmapImage4[i][j][2] = 0.0; } } for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { mipmapImage2[i][j][0] = 0.2; mipmapImage2[i][j][1] = 0.0; mipmapImage2[i][j][2] = 0.0; } } mipmapImage1[0][0][0] = 0.1; mipmapImage1[0][0][1] = 0.0; mipmapImage1[0][0][2] = 0.0; } static GLuint texName; void init() { int i; for (i = 0; i < 64*64*3; i ++) buf[i]=2.2; //init w/ invalid value glMatrixMode(GL_PROJECTION); glLoadIdentity(); glTranslatef(-1.0, -1.0, 0.0); glScalef(2.0/WIN_WIDTH, 2.0/WIN_HEIGHT, 1.0); glClearColor(0, 0, 0, 0); glDisable(GL_DITHER); glEnable(GL_TEXTURE_2D); makeImages(); glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_FLOAT, mipmapImage64); glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 32, 32, 0, GL_RGB, GL_FLOAT, mipmapImage32); glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, 16, 16, 0, GL_RGB, GL_FLOAT, mipmapImage16); glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB, 8, 8, 0, GL_RGB, GL_FLOAT, mipmapImage4); glTexImage2D(GL_TEXTURE_2D, 4, GL_RGB, 4, 4, 0, GL_RGB, GL_FLOAT, mipmapImage4); glTexImage2D(GL_TEXTURE_2D, 5, GL_RGB, 2, 2, 0, GL_RGB, GL_FLOAT, mipmapImage2); glTexImage2D(GL_TEXTURE_2D, 6, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, mipmapImage1); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); } void display() { GLint ret_size; int i; glClear(GL_COLOR_BUFFER_BIT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, MY_MIN_LOD); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000); glBegin(GL_POLYGON); glTexCoord2f(0.0, 0.0); glVertex2i(0, 0); glTexCoord2f(0.0, 1.0); glVertex2i(0, SQUARE_SIDE); glTexCoord2f(1.0, 1.0); glVertex2i(SQUARE_SIDE, SQUARE_SIDE); glTexCoord2f(1.0, 0.0); glVertex2i(SQUARE_SIDE, 0); glEnd(); glReadPixels(0, 0, SQUARE_SIDE, SQUARE_SIDE, GL_RGB, GL_FLOAT, buf); for (i = 0; i < SQUARE_SIDE *SQUARE_SIDE*3; i+=3) { printf("R[%1.1f], G[%1.1f], B[%1.1f] \n", buf[i], buf[i+1], buf[i+2]); } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (WIN_WIDTH, WIN_HEIGHT); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init(); glutDisplayFunc(display); glutMainLoop(); }