Reputation: 101
i want to display an image(.png) in a frame in SDL.But,somehow only the frame appears and image does not get loaded.i am reading the image details from an XML file.this is the sample code i am trying:
Class myclass{
mysurface2(io.loadAndSet(myftndata->getXmlStr("backfile"), true) ),
myfframe(new fframe(img2, myftn->getXmlInt("backWidth"), myftn->getXmlInt("backHeight"), 0, 0)),
myobjects()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
throw string("SDL Error!!!: ");
}
atexit(SDL_Quit);
}
};
void myclass::drawImg() const {
SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255) );
SDL_Rect dest = {0, 0, 0, 0};
SDL_BlitSurface( screen, NULL, screen, &dest );
}
void myclass::move()
{
while ( not done )
{
drawImg();
SDL_Flip(screen);
}
}
Please note: i have an entire framework,which i cannot give here.The above is my code that i am trying.
Upvotes: 0
Views: 519
Reputation: 1016
You are blitting the screen to the screen, which is a zero-operation. You should change the first screen in the blit function to the SDL_Surface* that represents your image. Are you using a library (e.g. SDL_Image) for loading the .png file? Because SDL can only load .bmp files.
Upvotes: 1