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 111 112 113 114 115 116 117
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
typedef struct
{
char texte1[60];
char texte2[40];
}Texte;
void ScinderTexte(Texte *x, char testtexte[], int longueur);
SDL_Surface *Initialisation();
SDL_Surface *LoadImage32(const char *fichier_image);
void Apply_Surface(int x, int y, SDL_Surface *source, SDL_Surface *destination, SDL_Rect *clip);
int main(int argc, char *argv[])
{
SDL_Surface *screen = Initialisation();
TTF_Init();
TTF_Font *fontM = NULL;
fontM = TTF_OpenFont("MOD.ttf", 30);
SDL_Color noir = {0, 0, 0};
Texte test;
memset(&test,0,sizeof(test));
char testtexte[] = "Alors on va tester cette nouvelle fonction qui me semble etre deja vouer a bugger";
SDL_Surface *fond = LoadImage32("fond_jeu.bmp");
SDL_Surface *txt[3];
txt[0] = TTF_RenderText_Blended(fontM, testtexte, noir);
Apply_Surface(0, 0, fond, screen, NULL);
if (strlen(testtexte) < 40)
{
Apply_Surface(0, 100, txt[0], screen, NULL);
}
else
{
ScinderTexte(&test, testtexte, 46);
txt[1] = TTF_RenderText_Blended(fontM, test.texte1, noir);
txt[2] = TTF_RenderText_Blended(fontM, test.texte2, noir);
Apply_Surface(0, 100, txt[1], screen, NULL);
Apply_Surface(0, 150, txt[2], screen, NULL);
}
SDL_Flip(screen);
SDL_Delay(4000);
SDL_FreeSurface(fond);
SDL_Quit();
return 0;
}
void ScinderTexte(Texte *x, char testtexte[], int longueur)
{
x->texte1[longueur] = '\0';
x->texte2[0] = '\0';
int i =0;
for (i = 0; i <= strlen(testtexte); i++)
{
if (i < longueur)
{
x->texte1[i] = testtexte[i];
}
else
{
x->texte2[i - longueur] = testtexte[i];
}
}
}
SDL_Surface *Initialisation()
{
SDL_Surface *screen;
screen = SDL_SetVideoMode(1024, 640, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
printf("Can't init SDL: %s\n", SDL_GetError());
}
SDL_WM_SetCaption("Projet Eden", NULL);
return screen;
}
SDL_Surface *LoadImage32(const char *fichier_image)
{
SDL_Surface *image_optimized;
SDL_Surface *image_tmp = SDL_LoadBMP(fichier_image);
if (image_tmp == NULL)
{
printf("Image %s introuvable !\n", fichier_image);
system ("pause");
exit(-1);
}
image_optimized = SDL_DisplayFormat(image_tmp);
SDL_FreeSurface(image_tmp);
return image_optimized;
}
void Apply_Surface(int x, int y, SDL_Surface *source, SDL_Surface *destination, SDL_Rect *clip)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, clip, destination, &offset);
} |
Partager