I am working through the 7th tutorial on LazyFoo's SDL tutorials on SDL
http://lazyfoo.net/SDL_tutorials/index.php[
^]. I have made sure that the header and library files are in the proper location in my SDL folder. I also have include all the dll's in the project folder with my exe. I tried commenting out all my return statements to see if one of the conditions was being tripped to return. everything looks fine but I cannot get the window to stay open and display the background with text on it. I am using codeblocks as my IDE.
/*This source code copyrighted by Lazy Foo' Productions (2004-2013)
and may not be redistributed without written permission.*/
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include <string>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Surface *background = NULL;
SDL_Surface *message = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;
TTF_Font *font = NULL;
SDL_Color textColor = { 255, 255, 255 };
SDL_Surface *load_image( std::string filename )
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = IMG_Load( filename.c_str() );
if( loadedImage != NULL )
{
optimizedImage = SDL_DisplayFormat( loadedImage );
SDL_FreeSurface( loadedImage );
if( optimizedImage != NULL )
{
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
}
}
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface( source, clip, destination, &offset );
}
bool init()
{
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
if( screen == NULL )
{
return false;
}
if( TTF_Init() == -1 )
{
return false;
}
SDL_WM_SetCaption( "TTF Test", NULL );
return true;
}
bool load_files()
{
background = load_image( "background.png" );
font = TTF_OpenFont( "lazy.ttf", 28 );
if( background == NULL )
{
return false;
}
if( font == NULL )
{
return false;
}
return true;
}
void clean_up()
{
SDL_FreeSurface( background );
SDL_FreeSurface( message );
TTF_CloseFont( font );
TTF_Quit();
SDL_Quit();
}
int main( int argc, char* args[] )
{
bool quit = false;
if( init() == false )
{
return 1;
}
if( load_files() == false )
{
return 1;
}
message = TTF_RenderText_Solid( font, "The quick brown fox jumps over the lazy dog", textColor );
if( message == NULL )
{
return 1;
}
apply_surface( 0, 0, background, screen );
apply_surface( 0, 150, message, screen );
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
while( quit == false )
{
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
quit = true;
}
}
}
clean_up();
return 0;
}