I am working through Lazy Foo's tutorials on SDL, and I was on lesson 4 (Event Driven Programming) and everything was going exactly how it should have been going, untill I tried to run my program. The program would run like it was supposed to, meaning that there were no warnings about improper sintax or missing DLLs or anything like that, but all I was seeing was a blank window pop up.
The program is supposed to show a picture (in my case a tree but that isn't important), and stay open untill I hit the X in the upper right hand corner, but for some reason it's not doing either of those. Like I said I'm seeing a blank screen, but the program also won't close when told to. I'm able to close it through stopping the debug, but that's not how it's supposed to work.
I've attached the program file here: [attachment=14025:Events.zip] so that you can see if I've missed something there, and here is the code in case you can't open the files on your computer:
#include "SDL.h"
#include "SDL_image.h"
#include <string>
const int ScreenWidth = 640;
const int ScreenHeight = 480;
const int ScreenBPP = 32;
SDL_Surface* Image = NULL;
SDL_Surface* Screen = NULL;
//SDL event structure
SDL_Event Event;
SDL_Surface* load_image(std::string filename)
{
//Load Image
SDL_Surface* LoadedImage = NULL;
//Optimize
SDL_Surface* OptimizedImage = NULL;
//load image with SDL image
LoadedImage = IMG_Load(filename.c_str());
//if the image loaded fine
if (LoadedImage != NULL)
{
//create the optimized image
OptimizedImage = SDL_DisplayFormat(LoadedImage);
//free the old image
SDL_FreeSurface(LoadedImage);
}
//return the optimized image
return OptimizedImage;
}
void ApplySurface(int x, int y, SDL_Surface* Source, SDL_Surface* Destination)
{
//temp rectangle to hold offsets
SDL_Rect offset;
//get the offsets
offset.x;
offset.y;
//blit to the surface
SDL_BlitSurface(Source,NULL,Destination,&offset);
}
bool Init()
{
//terminate program if init fails
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return false;
}
//set up the screen
Screen = SDL_SetVideoMode(ScreenWidth, ScreenHeight, ScreenBPP, SDL_SWSURFACE);
//if the screen failed to start
if(Screen == NULL)
{
return false;
}
//Set the window caption
SDL_WM_SetCaption("Event Test",NULL);
//if everything went fine
return true;
}
bool LoadFiles()
{
//load the image
Image = load_image("Tree.png");
//if there was an error
if (Image == NULL)
{
return false;
}
//if everything loaded properly
return true;
}
void Cleanup()
{
//free the image
SDL_FreeSurface(Image);
//quit SDL
SDL_Quit();
}
int main (int argc, char* args[])
{
//make sure the program doesn't terminate immediately
bool Quit = false;
//initialize
if (Init() == false)
{
return 1;
}
//load the image
if (LoadFiles() == false)
{
return 1;
}
//apply the surface
ApplySurface(0,0,Image,Screen);
//update the screen
if (SDL_Flip(Screen) == -1)
{
return 1;
}
//start main loop
while (Quit == false)
{
//get input of some kind
while (SDL_PollEvent(&Event))
{
//if user X's out
if (Event.type == SDL_QUIT)
{
//quit the program
Quit == true;
}
}
}
//free the surface and quit the program
Cleanup();
return 0;
}
Any help would be apreciated. Thank you in advance.