I am trying to create a program that is supposed to make specified colors transparent based off of Lazy Foo's 5th SDL tutorial for Windows, Visual c++ 2010 express, but I've run into a problem. The pictures that I have specified aren't showing up at all. I have all of the neccesary files where they need to be, and I have checked through the code twice at least, comparing it to previous projects and the tutorial, and looking for my usual mistakes (using == where I should be using =, simple spelling mistakes, ETC.) but I can't find anything. I may just be dense and am missing a single character somewhere in this code, but I would appreciate any help that can be given.
Thank you for your time, here is the code:
#include "SDL.h"
#include "SDL_image.h"
#include <string>
const int ScreenWidth = 640;
const int ScreenHeight = 480;
const int ScreenBPP = 32;
SDL_Surface* Screen = NULL;
SDL_Surface* Background = NULL;
SDL_Surface* Image = NULL;
SDL_Event Event;
SDL_Surface* LoadImage(std::string filename)
{
//the image that's loaded
SDL_Surface* LoadedImage = NULL;
//optimized image
SDL_Surface* OptimizedImage = NULL;
//load the image
LoadedImage = IMG_Load(filename.c_str());
//if the image loaded
if(LoadedImage != NULL)
{
//create the optimized image
OptimizedImage = SDL_DisplayFormat(LoadedImage);
//Free the old image
SDL_FreeSurface(LoadedImage);
}
return OptimizedImage;
}
//apply the surfaces to the screen
void ApplySurface (int x, int y, SDL_Surface* Source,SDL_Surface* Destination)
{
//temp rect
SDL_Rect offset;
//get the offsets
offset.x = x;
offset.y = y;
//blit the surface
SDL_BlitSurface(Source,NULL,Destination,&offset);
}
bool Init()
{
//initialize SDL
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return false;
}
//initialize the screen
Screen = SDL_SetVideoMode(ScreenWidth,ScreenHeight,ScreenBPP,SDL_SWSURFACE);
//if screen initialazation failed
if(Screen == NULL)
{
return false;
}
//set window caption
SDL_WM_SetCaption("WOOOHOOO FOR NO BOXES!!",NULL);
//if everything is right
return true;
}
bool LoadFiles()
{
//load the background
Background = LoadImage("Background.png");
//if there was an error
if(Background == NULL)
{
return false;
}
//load the image
Image = LoadImage("Tree.png");
if(Image == NULL)
{
return false;
}
//if everything loaded properly
return true;
}
void Cleanup()
{
//free the background
SDL_FreeSurface(Image);
//free the image
SDL_FreeSurface(Background);
//quit SDL
SDL_Quit();
}
int main (int argc,char* args[])
{
//keep the program active
bool Quit = false;
//initialize
if(Init() == false)
{
return 1;
}
//load the image
if(LoadFiles == false)
{
return 1;
}
//apply the surface
ApplySurface(0,0,Background,Screen);
ApplySurface(320,240,Image,Screen);
//flip the screen
if(SDL_Flip(Screen) == -1)
{
return 1;
}
//start the loop
while (Quit == false)
{
//get input
while (SDL_PollEvent(&Event))
{
if(Event.type == SDL_QUIT)
{
Quit = true;
}
}
}
//free the surfaces
Cleanup();
return 0;
}