0
votes

I am having trouble cube mapping when using a DDS cube map, I'm just getting a black cube which leads me to believe I have missing something simple, here's the code so far:

DDS_IMAGE_DATA *pDDSImageData = LoadDDSFile(filename);
//compressedTexture = -1;

if(pDDSImageData != NULL)
{
    int height = pDDSImageData->height;
    int width = pDDSImageData->width;
    int numMipMaps = pDDSImageData->numMipMaps;
    int blockSize;

    GLenum cubefaces[6] = {
        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,
    };

    if( pDDSImageData->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT )
        blockSize = 8;
    else
        blockSize = 16;
    glGenTextures( 1, &textureId ); int nSize;
    int nOffset = 0;
    glEnable(GL_TEXTURE_CUBE_MAP);
    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);

    for(int face = 0; face < 6; face++)
    {
        for( int i = 0; i < numMipMaps; i++ )
        {
            if( width  == 0 ) width  = 1;
            if( height == 0 ) height = 1;
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
            nSize = ((width+3)>>2) * ((height+3)>>2) * blockSize;

            glCompressedTexImage2D(cubefaces[face] ,
                i,
                pDDSImageData->format,
                width,
                height,
                0,
                nSize,
                pDDSImageData->pixels + nOffset );


            nOffset += nSize;

            // Half the image size for the next mip-map level...
            width  = (width  / 2);
            height = (height / 2);
        }
    }
}

Once this code is called I bind the texture using glBindTexture and draw a cube using GL_QUADS and glTexCoord3f.

1
Does it work when using non-DDS cubemaps, or you have this problem in general? Are you using 3d texture coordinates? - UncleZeiv
I haven't tried it for non-DDS and I amusing 3d texture coordinates. - paj777

1 Answers

0
votes

I'm get running my compressed dds-files with a cube. Your code is right, but have you layout your planes from your cube in the right orientation? Remember, you are IN the cube.

Try this in your display routine (in java):

gl.glEnable(GL2.GL_TEXTURE_CUBE_MAP);
gl.glBindTexture( GL2.GL_TEXTURE_CUBE_MAP, textureObjects[0] );
gl.glCullFace(GL2.GL_FRONT);

gl.glBegin(GL2.GL_QUADS);

// Negative-X Quad with map from Positive-X
// the veritices clockwise and the
// map counterclockwise 
gl.glTexCoord3f(  1.0f, -1.0f, 1.0f  );
gl.glVertex3f( -size, -size, size );
gl.glTexCoord3f( 1.0f, 1.0f, 1.0f  );
gl.glVertex3f( -size, size, size );
gl.glTexCoord3f(  1.0f, 1.0f, -1.0f  );
gl.glVertex3f( -size, size, -size );
gl.glTexCoord3f(  1.0f, -1.0f, -1.0f  );
gl.glVertex3f( -size, -size, -size );
/* ... */
gl.glEnd();  

gl.glCullFace(GL2.GL_BACK);
gl.glDisable(GL2.GL_TEXTURE_CUBE_MAP);