Jump to content
  • Advertisement
Sign in to follow this  
SteveDeFacto

How to load a DDS cube mapwith FreeImage?

This topic is 2688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color="#555555"][font="arial, helvetica, clean, sans-serif"]I have a cube map in a single DDS file but I see no way to load a DDS cube map with FreeImage. Does FreeImage support this and if so then what command replaces GetBits to get each side of the cube? Also is there a command to get whether the file is 2d, 3d or a cube map? Here is my function currently:[/font]
[color="#555555"][font="arial, helvetica, clean, sans-serif"] [/font]
[color="#555555"][font="arial, helvetica, clean, sans-serif"] [/font]
[font="arial, helvetica, clean, sans-serif"][color="#555555"]

Ovgl::Texture* Ovgl::MediaLibrary::ImportTexture( const std::string& file )
{
// Create new texture
Ovgl::Texture* texture = new Ovgl::Texture;

// Set the texture's media library handle to this media library
texture->MLibrary = this;

// Image format
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;

// Check the file signature and deduce its format
fif = FreeImage_GetFileType( file.c_str(), 0 );

// If still unknown, try to guess the file format from the file extension
if( fif == FIF_UNKNOWN )
{
fif = FreeImage_GetFIFFromFilename( file.c_str() );
}

// If still unkown, return NULL
if( fif == FIF_UNKNOWN )
{
return NULL;
}

// Load texture
FIBITMAP* dib = FreeImage_Load( fif, file.c_str() );

// Convert to RGB format
dib = FreeImage_ConvertTo32Bits( dib );

// Get raw data and dimensions
BYTE* data = FreeImage_GetBits( dib );
DWORD width = FreeImage_GetWidth( dib );
DWORD height = FreeImage_GetHeight( dib );

// Create OpenGL texture
if() // if 2d texture
{
glGenTextures( 1, &texture->Image );
glBindTexture( GL_TEXTURE_2D, texture->Image );
glTexImage2D( GL_TEXTURE_2D, 1, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );
}
else if() // if 3d texture
{
glGenTextures( 1, &texture->Image );
glBindTexture( GL_TEXTURE_3D, texture->Image );
glTexImage2D( GL_TEXTURE_3D, 1, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );
}
else if() // if cubemap
{
glBindTexture(GL_TEXTURE_CUBE_MAP, texture->Image);
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);
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_POSITIVE_X, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, data);
}

// Release FreeImage's copy of the image
FreeImage_Unload( dib );

// Add texture to media library
Textures.push_back( texture );

// Return texture pointer
return texture;
}

[/font]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!