Frage zu SDL_TTF



  • Hallo zusammen,

    ich hab' mal versucht die Textausgabe-Funktion der SDL (TTF) zu benutzen.

    Irgendwie bekomm' ich aber nur einen schwarzen Bildschirm statt Schrift zu sehen 😞

    Hat da jemand einen Tipp?

    Hier die Code-Stelle:

    #include <iostream>
    #include "SDL/SDL.h"
    #include "grafik.hpp"
    #include "spieler.hpp"
    #include "SDL/SDL_ttf.h"
    #include <stdio.h>
    #include <stdlib.h>
    
    using namespace std;
    
    //The attributes of the screen
    const int SCREEN_WIDTH = 1200;  // Hier wird die Größe des Ausgabebildschirms festgelegt....
    const int SCREEN_HEIGHT = 800;
    const int SCREEN_BPP = 32;  //SCREEN_BPP is the bits per-pixel. In all of the tutorials, 32-bit color will be used.
    
    float time1, time2, time_gesamt;
    float gewaehlte_framerate = 25;
    float puffer_framerate;
    int test;
    int contador1=0;
    bool game=true;
    
    SDL_Surface *screen, *osito_vorne = NULL; // Pointer auf Null setzen
    SDL_Rect dest2;
    SDL_Event event;
    Uint8 *keys;
    Spieler *p_Spieler1 = NULL;
    //class Spieler;
    
    //TTF Sachen:
    TTF_Font *fuente;
    const char texto[14]="Hola Mundo...";
    char msg[14];
    SDL_Color bgcolor,fgcolor;
    SDL_Surface *ttext;
    
     int main( int argc, char* args[] ) // SDL brauch diese Parameter
    {
        cout << "hallo" << endl; // Wie schreib ich in die Konsole? -> SDL leitet das ganze in eine Textdatei um, die sich im bin-Ordner befindet
    
        // INITIALISIERUNG VON SDL
        if (SDL_Init ( SDL_INIT_EVERYTHING ) == -1)
            cout << "Fehler in der SDL-Initialisierung" << endl;
    
        screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); // Zeiger wird initialisiert
        SDL_WM_SetCaption( "Artes marciales", NULL );
    
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    cout << "TTF Error" << endl;
    return 1;
    }
    fuente = TTF_OpenFont("Dragonwick.ttf",20);
    
    // inicializa colores para el texto
    fgcolor.r=200;
    fgcolor.g=200;
    fgcolor.b=10;
    bgcolor.r=255;
    bgcolor.g=100;
    bgcolor.b=100;
    
    sprintf(msg,"%s",texto);
    ttext = TTF_RenderText_Shaded(fuente,msg,fgcolor,bgcolor);
    
    dest2.x = 200; // X-Position des Rechtecks
    dest2.y = 400;  // y-Koordinate
    dest2.w = 200;  // Breite
    dest2.h = 200;   // Höhe des Rechtecks
    
    SDL_BlitSurface(ttext, NULL, screen, &dest2);
    SDL_Flip(screen);
    SDL_Delay(2000);
    //void TTF_Quit(void);
    


  • Hat sich schon erledigt...
    hab' in Zeile 53 nochmal SDL_Video initalisiert... sollte aber SDL_TTF sein 😮

    if (TTF_Init() < 0) {
    cout << "TTF Error" << endl;
    return 1;
    }
    

    Jetzt geht's 😉


Anmelden zum Antworten