1

I make a SDL_ttf test code:

#include <SDL.h>
#include <stdbool.h>
#include <iostream>
#include "SDLwindow.h"
#include <SDL_ttf.h>
#include "GraphLib.h"
#undef main

using namespace std;


int main() {

    bool running = 1;

    
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
    TTF_Init();


    WindowSDL window1;
    TTF_Font* font = TTF_OpenFont("./acme.ttf", 10);
    SDL_Surface* textSurf = TTF_RenderText_Solid(font, "Hola mundo", {255,0,0});
    SDL_Texture* textTexture = SDL_CreateTextureFromSurface(window1.renderer, textSurf);

    SDL_FreeSurface(textSurf);
    SDL_Rect textRect;
    textRect.x = 10;
    textRect.y = 10;
    textRect.w = 400;
    textRect.h = 100;
    //TTF_CloseFont(font);

    window1.CreateWindow("Pix", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 600, SDL_WINDOW_BORDERLESS);
    window1.CreateRenderer(window1.window, -1, 0);


    window1.ChangeBackgroundColor(0xe0e0e0);

    drawLine(window1, 3, 3, 40, 50, 0x0aaf88, 0);
    drawLine(window1, 40, 50, 80, 3, 0x0aaf88, 0);
    drawLine(window1, 80, 3, 3, 3, 0x0aaf88, 0);

    SDL_RenderCopy(window1.renderer, textTexture, NULL, &textRect);
    SDL_RenderPresent(window1.renderer);


    while (running) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = 0;
            }
        }

    }

    window1.Shutdown();
    TTF_Quit();

    return 0;
}

...and... boom it doesn't appear, heres my screen:

screen image

I tried to change the order of certain lines like TTF_Init(); and so on, the results were the same, it does not appear on the screen

genpfault
  • 51,148
  • 11
  • 85
  • 139
Nico Cano
  • 37
  • 3
  • 1
    Maybe learning how to debug is more effective than watching videos. Is `acme.ttf` present in your working directory? How about checking return value of `TTF_OpenFont`, `TTF_RenderText_Solid` and `SDL_CreateTextureFromSurface`? Can you really expect anyone to know what (and when) your `WindowSDL` class does? To me it looks like you use renderer for texture creation way before the renderer is created, so it is probably invalid. – keltar Dec 22 '22 at 04:59
  • Thanks, I didn't realize that I was doing it before creating the renderer, I'm so stupid – Nico Cano Dec 22 '22 at 05:27

0 Answers0