PDA

View Full Version : Cube mapping problems



Roter_Fuchs
07-31-2012, 02:55 PM
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:

http://img3.imageshack.us/img3/6531/cubemapping.png

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

V-man
08-01-2012, 04:32 PM
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?


1. I don't know. I've never seen it.
2. Keep working on it. Check out the spec file for TGA, if one exists.
3. http://www.opengl.org/wiki/Related_toolkits_and_APIs
See "Image and Texture Libraries (http://www.opengl.org/wiki/Related_toolkits_and_APIs#Image_and_Texture_Librar ies)"

Roter_Fuchs
08-04-2012, 08:36 AM
Thanks for your answer.
After some more testing I decided to try out the "Simple OpenGL Image Library" SOIL (which seems to be really good). It didn't solve my problem completly, but at least it reduced the errors to a minimum.
Luckily a few days later - namely today - I stumbled upon the solution (while looking for something completly different):

glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS)

It fixed everything.

Regards,
Fuchs