void LoadCubeMap(const char *dir, const char *ext) { char path[FILENAME_MAX]; CubeTexParameters(GL_TEXTURE_CUBE_MAP); sprintf(path, "%s/left.%s", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, path); sprintf(path, "%s/right.%s", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_POSITIVE_X, path); sprintf(path, "%s/bottom.%s", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, path); sprintf(path, "%s/top.%s", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, path); sprintf(path, "%s/back.%s", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, path); sprintf(path, "%s/front.%s", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, path); }
void LoadCubeMap(const char *dir, const char *ext) { std::string path; CubeTexParameters(GL_TEXTURE_CUBE_MAP); io::sprintf(path, "{1}/left.{2}", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, path); io::sprintf(path, "{1}/right.{2}", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_POSITIVE_X, path); io::sprintf(path, "{1}/bottom.{2}", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, path); io::sprintf(path, "{1}/top.{2}", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, path); io::sprintf(path, "{1}/back.{[2}", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, path); io::sprintf(path, "{1}/front.{2}", dir, ext); LoadCubeFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, path); }
void NormalCubeMap(int power) { int size = 1 << power; int half = size >> 1; char map[6][size][size][3]; for (int i = 0; i < size; ++i) { double v = 0.5 + i - half; for (int j = 0; j < size; ++j) { double u = 0.5 + j - half; CubeMapPackPixel(map[0][i][j], +half, -v, -u); CubeMapPackPixel(map[1][i][j], -half, -v, +u); CubeMapPackPixel(map[2][i][j], +u, +half, +v); CubeMapPackPixel(map[3][i][j], +u, -half, -v); CubeMapPackPixel(map[4][i][j], +u, -v, +half); CubeMapPackPixel(map[5][i][j], -u, -v, -half); } } CubeTexParameters(GL_TEXTURE_CUBE_MAP); glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X ,0 ,GL_RGB ,size ,size ,0 ,GL_RGB ,GL_UNSIGNED_BYTE ,map[0] ); glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_X ,0 ,GL_RGB ,size ,size ,0 ,GL_RGB ,GL_UNSIGNED_BYTE ,map[1] ); glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Y ,0 ,GL_RGB ,size ,size ,0 ,GL_RGB ,GL_UNSIGNED_BYTE ,map[2] ); glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ,0 ,GL_RGB ,size ,size ,0 ,GL_RGB ,GL_UNSIGNED_BYTE ,map[3] ); glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Z ,0 ,GL_RGB ,size ,size ,0 ,GL_RGB ,GL_UNSIGNED_BYTE ,map[4] ); glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Z ,0 ,GL_RGB ,size ,size ,0 ,GL_RGB ,GL_UNSIGNED_BYTE ,map[5] ); }