#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 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); } #define CUBE_MAP_SIZE 64 static GLfloat vertex[4][3] = { {-CUBE_MAP_SIZE / 2, +CUBE_MAP_SIZE / 2, -CUBE_MAP_SIZE / 2}, {+CUBE_MAP_SIZE / 2, +CUBE_MAP_SIZE / 2, -CUBE_MAP_SIZE / 2}, {+CUBE_MAP_SIZE / 2, -CUBE_MAP_SIZE / 2, -CUBE_MAP_SIZE / 2}, {-CUBE_MAP_SIZE / 2, -CUBE_MAP_SIZE / 2, -CUBE_MAP_SIZE / 2}, }; #define I 2 static GLfloat positive_x_face[4][3] = { {+2, -2, +2}, {+2, -2, -2}, {+2, +2, -2}, {+2, +2, +2} }; static void test (void) { int i, j, faceIndex; int texName; GLfloat CubeMap[6][CUBE_MAP_SIZE][CUBE_MAP_SIZE][3]; GLfloat buf[WINDSIZEX * WINDSIZEY * 3]; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glGenTextures (1, &texName); glBindTexture (GL_TEXTURE_CUBE_MAP_ARB, texName); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); for (faceIndex = 0; faceIndex < 6; faceIndex++) { for (i = 0; i < CUBE_MAP_SIZE; i++) { for (j = 0; j < CUBE_MAP_SIZE; j++) { CubeMap[faceIndex][i][j][0] = faceIndex==0? 1.0:0.0; CubeMap[faceIndex][i][j][1] = faceIndex==4? 1.0:0.0; CubeMap[faceIndex][i][j][2] = 0.0; } } } for (j = 0; j < 6; j++) { glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + j, 0, GL_RGB, CUBE_MAP_SIZE, CUBE_MAP_SIZE, 0, GL_RGB, GL_FLOAT, CubeMap[j]); } glDisable (GL_TEXTURE_GEN_S); glDisable (GL_TEXTURE_GEN_T); glDisable (GL_TEXTURE_GEN_R); glEnable (GL_TEXTURE_CUBE_MAP_ARB); glColor3f (1.0, 1.0, 1.0); glBindTexture (GL_TEXTURE_CUBE_MAP_ARB, texName); glBegin (GL_POLYGON); for (i = 0; i < 4; i++) { glTexCoord3f (positive_x_face[i][0], positive_x_face[i][1], positive_x_face[i][2]); glVertex3f (vertex[i][0], vertex[i][1], vertex[i][2]); } glEnd (); glFlush (); printf ("read out pixels:\n"); glReadPixels (0, 0, WINDSIZEX, WINDSIZEY, GL_RGB, GL_FLOAT, buf); for (j = 0; j < WINDSIZEY; j++) { for (i = 0; i < WINDSIZEY; i++) { if (buf[(j * WINDSIZEX + i) * 3] != 0 || buf[(j * WINDSIZEX + i) * 3 + 1] != 0 || buf[(j * WINDSIZEX + i) * 3 + 2] != 0) { printf ("(%d, %d) = [%f, %f, %f]\n", i, j, buf[(j * WINDSIZEX + i) * 3], buf[(j * WINDSIZEX + i) * 3 + 1], buf[(j * WINDSIZEX + i) * 3 + 2]); } } } } void display (void) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (-50, 50, -50, 50, 0, 2048); 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; }