Hello folks,
lately I have been getting into OpenGL. I have tried using cubemaps and have stumbled upon some weird errors.
I have been using a tutorial coming straight from the OpenGL SuperBible Edition 5, which is somehow not working as intended.
Well, my problem literally looks like this:
If you shift that faulty looking part on the right to the one on the left, you notice that it fits.
Anyways, not done. I guess my problem originates from this:
void Skybox::SetTexture(const char* szCubeFaces[6])
{
glGenTextures(1, &cubeTexture);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTexture);
// Set up preferences
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
GLbyte* pBytes;
GLint iWidth;
GLint iHeight;
GLint iComponents;
GLenum eFormat;
GLenum cube[] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
// Load Cube Map images
for(int i = 0; i < 6; i++)
{
//Load this texture mapj
//pBytes = gltReadTGABits(szCubeFaces[i], &iWidth, &iHeight, &iComponents, &eFormat);
//glTexImage2D(cube[i], 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes);
FILE* pFile = fopen(szCubeFaces[i], "rb");
pBytes = (GLbyte*)malloc(512*512*4 * sizeof(GLbyte));
fread(pBytes, 512*512*4, 1, pFile);
glTexImage2D(cube[i], 0, GL_RGB, 512, 512, 0, GL_BGR, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);
}
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
}
I took the tga image loading function straight from the superbible, no modifications. Sadly it does not seem to work. After doing some debugging I figured that, after loading the texture, the function decided that the bits in the tgaHeader are -52. Cannot work of course. I threw together a few lines of code to load the tga myself and et voilá it loaded. Just not… good enough.
So I am wondering, why is the tga loading function from the superbible faulty?
Where do these errors come from when using my own small loading code?
Can you suggest some good image loading libraries that work well together with OpenGL?
Any help is greatly appreciated.
Greetings,
Fuchs