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
|
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "SDL/SDL_ttf.h"
//#include <SDL/SDL_image.h>
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL;// *fond = NULL;
SDL_Event event;
int continuer = 1;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Gestion du texte avec SDL_ttf", NULL);
SDL_version compile_version;
const SDL_version *link_version=TTF_Linked_Version();
SDL_TTF_VERSION(&compile_version);
printf("compiled with SDL_ttf version: %d.%d.%d\n",
compile_version.major,
compile_version.minor,
compile_version.patch);
printf("running with SDL_ttf version: %d.%d.%d\n",
link_version->major,
link_version->minor,
link_version->patch);
/* Chargement de la police */
SDL_Surface *texte = NULL;
SDL_Rect position;
TTF_Font *police = NULL;
SDL_Color couleurNoire = {0, 0, 0};
//TTF_Init();
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
police = TTF_OpenFont("TEAMSPIR.ttf", 35);
/* Ecriture du texte dans la SDL_Surface "texte" en mode Blended (optimal) */
texte = TTF_RenderText_Blended(police, "S", couleurNoire);
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
// SDL_BlitSurface(fond, NULL, ecran, &position); /* Blit du fond */
position.x = 60;
position.y = 370;
SDL_BlitSurface(texte, NULL, ecran, &position); /* Blit du texte par-dessus */
SDL_Flip(ecran);
}
TTF_CloseFont(police);
TTF_Quit();
SDL_FreeSurface(texte);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager