[Solved] SDL image error?
Posted: Tue Mar 01, 2011 8:13 pm
I am currently in the process of making a SHMUP. I have a background ready to blit, but when I apply the background to the screen, it doesn't show up. I am flipping the screen, in case you were wondering. Also, when I test the image I am trying to use isn't NULL. I am using Code::Blocks on windows vista. My images are pngs and are in a folder titled "SHMUP." Directly inside SHMUP are my images, my project, and a SHMUP.exe file. Also in the SHMUP folder are the "bin" and "obj" folders. Inside bin is Debug, and inside Debug is another SHMUP.exe! There are also other dlls and files of those sort(I am on my iPod I can't completely remember) in bin/Debug. When I put my images in the directory of the other exe (bin/Debug) my program crashes and returns 3. I am so confused, I have done so much googling it's ridiculous. Does anyone think they can help?
Code: Select all
//classes.h (only the code that applies to my problem)
class ImageManager //loads and manages images
{
private:
SDL_Surface* playerShip, *miniShip, *medShip, *bigShip; //player and enemy
SDL_Surface* background;
SDL_Surface* miniBullet, *medBullet, *bigBullet;
public:
ImageManager();
~ImageManager();
SDL_Surface * get_image(imageType type);
};
//classes.cpp (part of code that applies to my error)
ImageManager::ImageManager()
{
//ships
playerShip = load_image("playerShip.png");
miniShip = load_image("miniShip.png");
medShip = load_image("medShip.png");
bigShip = load_image("bigShip.png");
//bullets
miniBullet = load_image("miniBullet.png");
medBullet = load_image("medBullet.png");
bigBullet = load_image("bigBullet.png");
//other
background = load_image("background.png");
}
SDL_Surface* ImageManager::get_image(imageType type)
{
switch(type)
{
case EplayerShip:
return playerShip;
break;
case EminiShip:
return miniShip;
break;
case EmedShip:
return medShip;
break;
case EbigShip:
return bigShip;
break;
case Ebackground:
return background;
break;
case EminiBullet:
return miniBullet;
break;
case EmedBullet:
return medBullet;
break;
case EbigBullet:
return bigBullet;
break;
default: break;
}
return NULL;
}
ImageManager::~ImageManager()
{
//ships
SDL_FreeSurface(playerShip);
SDL_FreeSurface(miniShip);
SDL_FreeSurface(medShip);
SDL_FreeSurface(bigShip);
//bullets
SDL_FreeSurface(miniBullet);
SDL_FreeSurface(medBullet);
SDL_FreeSurface(bigBullet);
//other
SDL_FreeSurface(background);
}
//main.cpp
int SDL_main(int argc, char *argv[])
{
set_up();
ImageManager imageMan;
SDL_Surface * background = imageMan.get_image(Ebackground);
bool quit = false;
while(quit==false)
{
//background's area
SDL_Rect backgroundClips;
backgroundClips.x = 0;
backgroundClips.y = 0;
backgroundClips.w = 640;
backgroundClips.h = 480;
//banner
SDL_Rect banner;
banner.x = 0;
banner.y = 0;
banner.w = 640;
banner.h = 30;
apply_surface(0,30,background,screen,&backgroundClips);
SDL_FillRect(screen,&banner,SDL_MapRGB(screen->format,40,60,180));
SDL_Flip(screen);
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
quit = true;
}
}
}
clean_up();
return 0;
}