Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Cube mapping problems

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    3

    Cube mapping problems

    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:

    Code :
    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

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Quote Originally Posted by Roter_Fuchs View Post
    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"
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •