Skip to content
Snippets Groups Projects
Commit ce323bb6 authored by mathieu's avatar mathieu
Browse files

affichage hello world compris et fait

parent 7b80c7cd
Branches master
No related tags found
No related merge requests found
#include "util_sdl.h"
#define PATH_FONT "/home/local.isima.fr/mavilledie4/shared/projetZ1/exemples_executables/fonts/Pacifico.ttf"
#define TAILLE_FONT 65
int main()
{
......@@ -37,13 +38,47 @@ int main()
if (renderer == NULL)
if (end_sdl(0, "ERROR RENDERER CREATION", window, renderer) == -1)
return EXIT_FAILURE;
/******* fin initialisation de la sdl *************/
if (TTF_Init() < 0)
if (end_sdl(0, "Couldn't initialize SDL TTF", window, renderer) == -1)
return EXIT_FAILURE;
/******* fin initialisation de la sdl *************/
TTF_Font *font = NULL; // la variable 'police de caractère'
font = TTF_OpenFont(PATH_FONT, TAILLE_FONT); // La police à charger, la taille désirée
if (font == NULL)
if (end_sdl(0, "Can't load font", window, renderer) == -1)
return EXIT_FAILURE;
TTF_SetFontStyle(font, TTF_STYLE_ITALIC ); // en italique, gras
SDL_Color color = {250, 250, 250, 255}; // la couleur du texte
SDL_Surface *text_surface = NULL; // la surface (uniquement transitoire)
text_surface = TTF_RenderText_Blended(font, "Hello World !", color); // création du texte dans la surface
if (text_surface == NULL)
if (end_sdl(0, "Can't create text surface", window, renderer) == -1)
return EXIT_FAILURE;
SDL_Texture *text_texture = NULL; // la texture qui contient le texte
text_texture = SDL_CreateTextureFromSurface(renderer, text_surface); // transfert de la surface à la texture
if (text_texture == NULL)
end_sdl(0, "Can't create texture from surface", window, renderer);
SDL_FreeSurface(text_surface); // la texture ne sert plus à rien
SDL_Rect pos = {0, 0, 0, 0}; // rectangle où le texte va être positionné
SDL_QueryTexture(text_texture, NULL, NULL, &pos.w, &pos.h); // récupération de la taille (w, h) du texte
SDL_GetWindowSize(window, &pos.x, &pos.y);
pos.x = (pos.x - pos.w) / 2;
pos.y = (pos.y - pos.h) / 2;
SDL_RenderCopy(renderer, text_texture, NULL, &pos); // Ecriture du texte dans le renderer
SDL_DestroyTexture(text_texture); // On n'a plus besoin de la texture avec le texte
SDL_RenderPresent(renderer);
SDL_Delay(2000);
SDL_DestroyTexture(text_texture);
TTF_Quit();
end_sdl(1, "fermeture ok", window, renderer);
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment