CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Affichage de variable avec SDL_TTF

thesuperbest
thesuperbest
Niveau 8
24 mars 2005 à 18:10:08

Tout est dans le titre : je voudrais savoir comment afficher une variable à l´écran avec SDL_TTF. Je sais déjà comment afficher un char* grace à ce tuto : http://prografix.games-creators.org/document/166 mais ça m´aiderais que vous me dites comment afficher un int, un float, . ..

pandamark
pandamark
Niveau 6
24 mars 2005 à 18:18:17

Avec sprintf()

  1. include < stdlib.h>

. . .
int valeur=500; / * par exemple*/
char strvaleur[16];
sprintf(strscore,"Score : %d",score);

/ *Puis tu mets affiche sur l´ecran*/

Celle ci de vengeur marche mieux l´autre bug:

  1. include < SDL/SDL.h>
  2. include < SDL/SDL_TTF.h>

SDL_Surface *Screen;
TTF_Font *font;
/ * Fonction */
void vTexte(char *message, short x, short y, char *font_face, short font_size, Uint8 r, Uint8 g, Uint8 b)
{
SDL_Color color;
SDL_Color colorShaded;
SDL_Surface *text;
SDL_Rect Rectangle_Destination;

color.r=r;
color.g=g;
color.b=b;

font=TTF_OpenFont(font_face, font_size);
if ( ! font)
{
fprintf(stderr, " Erreur : impossible de charger la police de caractères font.ttf ( Arial) \n");
exit(2);
}
text = TTF_RenderText_Solid(font, message, color);
if ( ! text)
SDL_Quit();

Rectangle_Destination.x = x;
Rectangle_Destination.y = y;
Rectangle_Destination.w = text->w;
Rectangle_Destination.h = text->h;

SDL_BlitSurface(text, NULL, Screen, &_Destination);

SDL_FreeSurface(text);
TTF_CloseFont(font);
}

int main ( int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
Screen = SDL_SetVideoMode(320,240,16,SDL_HWSURFACE);
SDL_WM_SetCaption("TILETEST",NULL);
vTexte("J´aime la tarte aux fraises",0,0,"font.ttf",12,255,255,255);
SDL_Flip(Screen);
SDL_Delay(5000);
SDL_Quit();
return 0;
}

jejej
jejej
Niveau 9
24 mars 2005 à 18:24:34

merci !
moi , avant , je faisais un itoa ( conversion entier -> char )
pas très pratique :)

Sous forums
  • Aide à l'achat Mac
  • Steam Deck
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Internet
  • Macintosh
  • Hardware
La vidéo du moment