1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| #include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_image.h>
#include <string>
SDL_Surface *load_image (std::string filename);
void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination);
void pause();
int main ( int argc, char** argv )
{
SDL_Surface *screen = NULL;
SDL_Surface *background = NULL;
SDL_Surface *message = NULL;
TTF_Font *font;
SDL_Color text_color = { 256 , 256 , 256 };
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return EXIT_FAILURE;
}
screen = SDL_SetVideoMode(400,254,32,SDL_HWSURFACE);
if(screen == NULL)
{
return EXIT_FAILURE;
}
if(TTF_Init() == -1)
{
return EXIT_FAILURE;
}
SDL_WM_SetCaption("Test de TTF",NULL);
background = load_image("Background.png");
if(background == NULL)
{
return EXIT_FAILURE;
}
font = TTF_OpenFont("ariblk.ttf",28);
if(font == NULL)
{
return EXIT_FAILURE;
}
message = TTF_RenderText_Solid(font, "Mortal Kombat" , text_color);
if(message == NULL)
{
return EXIT_FAILURE;
}
apply_surface(0,0,background,screen);
apply_surface(90,122,message,screen);
if(SDL_Flip(screen) == -1)
{
return EXIT_FAILURE;
}
pause();
SDL_FreeSurface(background);
SDL_FreeSurface(message);
TTF_CloseFont(font);
TTF_Quit();
SDL_Quit();
return 0;
}
SDL_Surface *load_image (std::string filename)
{
SDL_Surface *loadimage = NULL;
SDL_Surface *optimized_image = NULL;
loadimage = IMG_Load(filename.c_str());
if(loadimage != NULL)
{
optimized_image = SDL_DisplayFormat(loadimage);
SDL_FreeSurface(loadimage);
}
return optimized_image;
}
void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source,NULL,destination,&offset);
}
void pause()
{
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
}
}
} |
Partager