PDA

View Full Version : Load GL_TEXTURE_CUBE_MAP



fau78
05-22-2011, 07:47 PM
Hey,

I want to load a cube texture for cubic environment mapping. And I load 6 pictures in for 6 faces under same texture ID (here is 1) which is called by glBindTexture(). And I think it has some problem.

And this is my code:


glBindTexture (GL_TEXTURE_CUBE_MAP , 1);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexParameteri (GL_TEXTURE_CUBE_MAP , GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_CUBE_MAP , GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_CUBE_MAP , GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_CUBE_MAP , GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData1);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData2);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData3);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData4);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData5);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, texFormat, imageWidth, imageHeight, 0, texFormat, GL_UNSIGNED_BYTE, imageData6);


The last line simply repeated 6 times for 6 faces which are loaded in imageData. I think it is fine for imageData1, imageData2...

Any ideas? Maybe this guy is correct but some parts else in my code is wrong... It may possible.

Thank you.

Alfonse Reinheart
05-22-2011, 08:33 PM
texFormat

Every time someone asks this question, I wish just a little harder that I could go back in time and find the people who wrote the glTexImage* and other pixel transfer stuff into the spec and smack them repeatedly.

You've fallen prey to one of the classic OpenGL blunders: mistaking the internal format (http://www.opengl.org/wiki/Image_Format) for the pixel transfer format (http://www.opengl.org/wiki/Pixel_Transfer#Pixel_format). You certainly aren't the first and you won't be the last.

There are certain cases where the internal format (your first use of texFormat) could in fact be the same as the pixel transfer format (the second use of texFormat), but there are many, many cases where they should not be the same. Never pass the same variable to both.

So, what is the value of texFormat?

fau78
05-22-2011, 08:52 PM
Thank you. It is my fault.

Actually the 'texFormat' is derived by a TGA loader which works fine. It should either be GL_RGB or GL_RGBA depends on the .tga picture detail.

I modified the loader, which was used to load a GL_TEXTURE_2D. According to my .tga file. It is GL_RGBA, and the number is 6408.

I think it is not the problem of that parameter.

mhagain
05-23-2011, 09:09 AM
I recently solved a nasty cubemap problem by loading the faces in the same order as the defines: px/nx/py/ny/pz/nz. I know that the spec says that load order shouldn't matter, and in most cases it didn't matter, but one particular driver refused to take the cubemap otherwise.

You don't say what the pwoblem you're having is, by the way, but you should also be glTexParameter'ing a GL_TEXTURE_WRAP_R and the param should be GL_CLAMP_TO_EDGE in all 3 cases (S/T/R).