Je fais des test sur la première version de la librairie SDL, plus particulièrement sur les TTF.
J'ai une erreur de segmentation que je n'arrive pas à déboguer dans mon code.
main.c :
Code : Tout sélectionner
// Inclusions
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
// Prototypes
void echec(const char* texte);
void succes(const char* texte);
// Fonction principale
int main(void) {
// Variables
SDL_Surface *ecran = NULL,
*texte = NULL;
SDL_Event event;
SDL_Rect position;
SDL_Color noir = {0, 0, 0};
TTF_Font *police = NULL;
int continuer = 1;
// Instructions
SDL_Init(SDL_INIT_VIDEO) == -1 ? echec("Video") : succes("Video");
TTF_Init() == -1 ? echec("TTF") : succes("TTF");
SDL_WM_SetIcon(IMG_Load("icone"), NULL);
SDL_WM_SetCaption("Gestion du texte avec TTF", NULL);
!(ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) ? echec("Ecran") : succes("Ecran");
police = TTF_OpenFont("angelina.ttf", 65);
texte = TTF_RenderText_Solid(police, "Test", noir);
while(continuer) {
SDL_WaitEvent(&event);
switch(event.type) {
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
continuer = 0;
break;
}
break;
case SDL_QUIT:
continuer = 0;
break;
}
position.x = ecran->w / 2;
position.y = ecran->h / 2;
SDL_BlitSurface(texte, NULL, ecran, &position);
SDL_Flip(ecran);
}
TTF_CloseFont(police);
TTF_Quit();
SDL_FreeSurface(ecran);
SDL_FreeSurface(texte);
SDL_Quit();
return EXIT_SUCCESS;
}
// Fonctions
void echec(const char* texte) {
fprintf(stderr, "%s : %s\n", texte, SDL_GetError());
SDL_Quit();
TTF_Quit();
exit(EXIT_FAILURE);
}
void succes(const char* texte) {
fprintf(stderr, "%s : ok\n", texte);
}
Code : Tout sélectionner
clang -std=c11 -lSDL -lSDL_ttf -lSDL_image -o main *.c && ./main
Code : Tout sélectionner
main.c:57:12: warning: 232 enumeration values not handled in switch: 'SDLK_UNKNOWN', 'SDLK_BACKSPACE', 'SDLK_TAB'... [-Wswitch]
switch(event.key.keysym.sym) {
^
1 warning generated.
Video : ok
TTF : ok
Ecran : ok
Erreur de segmentation (core dumped)