All pastes #264422 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-02 12:00 UTC
rendered paste body
//The headers 
#include "SDL/SDL.h" 
#include "SDL/SDL_image.h" 
#include "SDL/SDL_ttf.h"
#include <string>


//Screen attributes 

const int SCREEN_WIDTH = 800; 
const int SCREEN_HEIGHT = 600;
 const int SCREEN_BPP = 32; 
 
 //The surfaces 
 
 SDL_Surface *message = NULL;
 SDL_Surface *achtergrond = NULL;
 SDL_Surface *screen = NULL;

 // EventStructur
SDL_Event event;

//The font that's going to be used 
TTF_Font *font = NULL;

//The color of the font
SDL_Color textColor = { 255, 255, 255 }; 


// LOAD image FUNCTION

SDL_Surface *load_image( std::string filename ) 
{
    //Temporary storage for the image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;
    
    //Load the image
    loadedImage = IMG_Load( filename.c_str() );
    
    //If nothing went wrong in loading the image
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        //Free the old image
        SDL_FreeSurface( loadedImage );
    }
    
    //Return the optimized image
    return optimizedImage;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;
    
    //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &offset );
}

bool init() 
{ 
	
	//Initialize all SDL subsystems 
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) 
{ 
		return false; 
} 
	
	//Set up the screen 
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); 
	
	//If there was in error in setting up the screen 
	if( screen == NULL ) 
	
{ 
		return false; 
	
} 

	//Initialize SDL_ttf 
	if( TTF_Init() == -1 ) 
	{ 
		return false; 
	} 
	
	//Set the window caption 
	
	SDL_WM_SetCaption( "Login Tester", NULL ); 
	
	//If everything initialized fine 
	
	return true; 

}

bool load_files() 
{ 
	
	//Load the image 
	achtergrond = load_image( "achtergrond.bmp" ); 
	
	//If there was an error in loading the image 
	if( achtergrond == NULL ) 
	
{ 
		return false; 
} 

	//Open the font 
	font = TTF_OpenFont( "lazy.ttf", 28 );

	if (font == NULL) 
	{

		return false;

	}
	
	//If everything loaded fine 
	
	return true;

}

void clean_up() 
{

	//Free the image 
	SDL_FreeSurface( achtergrond ); 

	//Close the font that was used 
	TTF_CloseFont( font ); 
	
	//Quit 
	SDL_ttf;

	//Quit 
	SDL_Quit(); 
}