Hi,
Recently I have been experimenting with SDL_Image implementation into my program, simply because bmps do not support transparency and are too memory intensive. The problem I am facing with it is that it doesn't display images other than bmp. I have linked in the SDL_image.lib and .h file into my program, I assume I have missed something out in my program, here is the code I use:
part of the Sprite loading/drawing class
Further on, if required here is my menu class which inherits from the sprite loading/drawing class (I use the menu class in the main to display the images.)
Thanks in advance!
Recently I have been experimenting with SDL_Image implementation into my program, simply because bmps do not support transparency and are too memory intensive. The problem I am facing with it is that it doesn't display images other than bmp. I have linked in the SDL_image.lib and .h file into my program, I assume I have missed something out in my program, here is the code I use:
part of the Sprite loading/drawing class
SDL_Surface* SDL_Graphics::LoadImage(const char* ImageFileName)
{
SDL_Surface* Image = IMG_Load(ImageFileName);
return Image;
}
void SDL_Graphics::CloseImage(SDL_Surface* Image)
{
SDL_FreeSurface(Image);
}
void SDL_Graphics::BeginScene()
{
// Clear the screen
SDL_FillRect(m_screen,
NULL,
SDL_MapRGB(m_screen->format, m_BackgroundColorRed,
m_BackgroundColorGreen,
m_BackgroundColorBlue));
}
// This just displays the scene.
void SDL_Graphics::EndScene()
{
SDL_Flip(m_screen);
}
void SDL_Graphics::DrawSprite(SDL_Surface* imageSurface,
int srcX, int srcY,
int dstX, int dstY,
int width, int height)
{
SDL_Rect srcRect;
srcRect.x = srcX;
srcRect.y = srcY;
srcRect.w = width;
srcRect.h = height;
SDL_Rect dstRect;
dstRect.x = dstX;
dstRect.y = dstY;
dstRect.w = width;
dstRect.h = height;
SDL_BlitSurface(imageSurface, &srcRect, m_screen, &dstRect);
}
Further on, if required here is my menu class which inherits from the sprite loading/drawing class (I use the menu class in the main to display the images.)
Menu::Menu(SDL_Graphics* graphics,
int imageX, int imageY,
int width, int height,
const char* ImageFileName,
float x, float y) : m_graphics(graphics),
m_imageX(imageX), m_imageY(imageY),
m_width(width), m_height(height),
m_x(x), m_y(y)
{
m_image = m_graphics->LoadImage(ImageFileName);
}
Menu::~Menu()
{
m_graphics->CloseImage(m_image);
}
void Menu::draw()
{
m_graphics->DrawSprite(m_image,
m_imageX, m_imageY,
m_x, m_y,
m_width, m_height);
}
Thanks in advance!