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
| nclude <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL_ttf.h>
#define LARGEUR_WINDOW 600
#define LONGUEUR_WINDOW 800
void ExitWithError(const char* message);
void DestroyAndExitWithError(const char* message, SDL_Renderer* renderer, SDL_Window *window);
void afficherTexture(const char* chemin, SDL_Renderer* renderer, SDL_Window* window);
int main(int argc, char** argv)
{
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
ExitWithError("SDL n'a pas pu se lancer.");
}
window = SDL_CreateWindow("Titre de la fenetre", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, LONGUEUR_WINDOW, LARGEUR_WINDOW, 0);
if (window == NULL) {
ExitWithError("La fenetre n'a pas pu s'ouvrir.");
}
/*-----------------------------------------------------------*/
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
if (renderer == NULL) {
ExitWithError("Création rendu échoué.");
}
if (TTF_Init() == -1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
TTF_Font* police = NULL;
police = TTF_OpenFont("../../../../Desktop/polices/Outwrite.ttf", 65);
SDL_Color couleur = { 255, 255, 255 };
SDL_Surface* scoreSurface = { 0 };
if ((scoreSurface = TTF_RenderText_Solid(police, "1", couleur) == NULL)) {
TTF_CloseFont(police);
TTF_Quit();
DestroyAndExitWithError("TTF_RenderText_Solid", renderer, window);
}
SDL_Texture* Message = SDL_CreateTextureFromSurface(renderer, scoreSurface);
if (Message == NULL) {
TTF_CloseFont(police);
TTF_Quit();
DestroyAndExitWithError("SDL_CreateTextureFromSurface", renderer, window);
} |
Partager