Trouble using SDL_DisplayFormat()
Posted: Wed Mar 23, 2011 6:15 pm
Hey, so I've been trying to implement the SDL library, but I've run into a problem: SDL_DisplayFormat() isn't working! I stepped through my code, and the image seems to be loaded into temp, but when it gets passed to SDL_DisplayFormat, the function returns NULL. Any idea why this is? Or is there a way to further debug? It seemed to be working earlier, but I can't figure out what broke it.
temp and surface.sourceImg are SDL_Surface*.
temp and surface.sourceImg are SDL_Surface*.
Code: Select all
bool loadImage(string fileName, Image& surface, SDL_Rect tileSize, SDL_Rect imageSize)
{
// Load the un-optimized picture
SDL_Surface* temp = IMG_Load(fileName.c_str());
if(temp == NULL)
{
surface.sourceImg = NULL;
return false;
}
// Load the optimized picture
surface.sourceImg = SDL_DisplayFormat(temp);
if(surface.sourceImg == NULL)
{
SDL_FreeSurface(temp);
temp = NULL;
return false;
}
SDL_FreeSurface(temp);
// Initialize the rest of the Image class
imageSize.x = (imageSize.x / tileSize.x); // Convert from pixels to tiles
imageSize.y = (imageSize.y / tileSize.y);
surface.tileSize = tileSize; // Copy the tile size
surface.tileCount = imageSize.x * imageSize.y; // Calculate the tile count
surface.tiles[surface.tileCount]; // Initialize the tile array
for(int i = 0; i < surface.tileCount; i++) // Setup all the coordinates
{
surface.tiles[i].x = i % imageSize.x;
surface.tiles[i].y = i / imageSize.y;
}
return true;
}