Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with SDL_ttf 3.1.1 does not show a text with SDL3.dll 3.2.4 #513

Open
8Observer8 opened this issue Feb 18, 2025 · 13 comments
Open

Comments

@8Observer8
Copy link

8Observer8 commented Feb 18, 2025

I have built the current SDL3_ttf 3.1.1 with SDL 3.2.4 and FreeType 2.13.3 using VS 2022 but my example does not show a text. But when I replace SDL3.dll 3.2.4 with SDL3.dll 3.1.10 a text is shown.

@slouken
Copy link
Collaborator

slouken commented Feb 18, 2025

Can you provide a link to your example and the fonts you used?

@8Observer8
Copy link
Author

8Observer8 commented Feb 18, 2025

My steps: Setting up SDL3_ttf 3.1.1

I have copied arial.ttf from the C:\Windows\Fonts folder:

Image

Example:

#define SDL_MAIN_USE_CALLBACKS 1 // Use the callbacks instead of main()
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3_ttf/SDL_ttf.h>

// We will use this renderer to draw into this window every frame
static SDL_Window* window = NULL;
static SDL_Renderer* renderer = NULL;
static SDL_Texture* texture = NULL;

// This function runs once at startup
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[])
{
    if (!SDL_Init(SDL_INIT_VIDEO)) {
        SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    // Initialize the TTF library
    if (!TTF_Init()) {
        SDL_Log("Couldn't initialize TTF: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    if (!SDL_CreateWindowAndRenderer("English text using SDL3 and C",
        500, 500, 0, &window, &renderer)) //
    {
        SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    TTF_Font* font = TTF_OpenFont("assets/fonts/arial.ttf", 48);
    SDL_Color textColor(255, 255, 255);
    SDL_Surface* surface = TTF_RenderText_Blended(font, "Hello, World!", 13, textColor);
    texture = SDL_CreateTextureFromSurface(renderer, surface);
    SDL_DestroySurface(surface);

    return SDL_APP_CONTINUE; // Carry on with the program
}

// This function runs when a new event (mouse input, keypresses, etc) occurs
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
{
    if (event->type == SDL_EVENT_QUIT) {
        return SDL_APP_SUCCESS; // End the program, reporting success to the OS
    }
    return SDL_APP_CONTINUE; // Carry on with the program
}

// This function runs once per frame, and is the heart of the program
SDL_AppResult SDL_AppIterate(void* appstate)
{
    // Set the position where you want to draw the text
    float x = 10.f;
    float y = 10.f;

    // Create a rectangle to hold the texture dimensions
    SDL_FRect rect;
    SDL_GetTextureSize(texture, &rect.w, &rect.h);
    rect.x = x;
    rect.y = y;

    // SDL_RenderTexture(renderer, texture, NULL, NULL);
    // Clear the screen
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
    SDL_RenderClear(renderer);

    // Draw the text
    SDL_RenderTexture(renderer, texture, NULL, &rect);

    // Update the screen
    SDL_RenderPresent(renderer);
    return SDL_APP_CONTINUE;  /* carry on with the program! */
}

// This function runs once at shutdown
void SDL_AppQuit(void* appstate, SDL_AppResult result)
{
    // SDL will clean up the window/renderer for us
    TTF_Quit();
    SDL_Quit();
}

CMakeLists.txt

find_package(SDL3)
find_package(SDL3_ttf)
target_link_libraries(hello-sdl3-ttf PRIVATE SDL3_ttf::SDL3_ttf SDL3::SDL3)

# Copy the assets folder to the dist folder
add_custom_command(TARGET hello-sdl3-ttf POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_SOURCE_DIR}/assets $<TARGET_FILE_DIR:hello-sdl3-ttf>/assets)

@slouken
Copy link
Collaborator

slouken commented Feb 20, 2025

Can you double check you were able to open your font? I don't see any error checking there.

I changed your example to this:

TTF_Font *font = TTF_OpenFont("C:/Windows/Fonts/arial.ttf", 48);

and ran it using the latest SDL_ttf and SDL code from GitHub and it works here.

@8Observer8 8Observer8 changed the title Example with SDL 3.1.1 does not show a text with SDL3.dll 3.2.4 Example with SDL_ttf 3.1.1 does not show a text with SDL3.dll 3.2.4 Feb 20, 2025
@8Observer8
Copy link
Author

8Observer8 commented Feb 21, 2025

I will try to build SDL_ttf with MinGW and Emscripten and will write about the result later.

@8Observer8
Copy link
Author

It works for me:

TTF_Font *font = TTF_OpenFont("C:/Windows/Fonts/arial.ttf", 48);

Sorry and thank you very much!

@slouken
Copy link
Collaborator

slouken commented Feb 23, 2025

You’re welcome!

@8Observer8
Copy link
Author

8Observer8 commented Mar 7, 2025

@slouken hello! Could you try to reproduce the following steps on the video?

text-sdl3-ttf-exe.zip

sdl-does-not-show-text.mp4

SDL 3.2.6 was downloaded from Releases. It is VS version.
I use 3.1.10 because this path in my PATH: E:\libs\sdl-3.1.10-msvc\win\debug\bin

@8Observer8 8Observer8 reopened this Mar 7, 2025
@madebr
Copy link
Contributor

madebr commented Mar 7, 2025

Does this also happen with latest SDL3_TTF 3.2.0?
Its minimum required SDL3 version is 3.2.6.

The minimum required SDL3 version is not tested at runtime. Maybe we should?

@8Observer8
Copy link
Author

8Observer8 commented Mar 7, 2025

The same for SDL3_ttf.dll 3.2.0 and SDL.dll 3.2.8

@8Observer8
Copy link
Author

8Observer8 commented Mar 7, 2025

Source: text-sdl3-ttf.zip

@slouken
Copy link
Collaborator

slouken commented Mar 7, 2025

You don't check the return value of TTF_OpenFont(), are you sure the font is being loaded correctly?

@slouken
Copy link
Collaborator

slouken commented Mar 7, 2025

On my system both of the DLLs you provide work.

@slouken
Copy link
Collaborator

slouken commented Mar 7, 2025

If you modify the project to use a vendored copy of SDL, you can easily git bisect to see what commit in SDL broke this:

# set the output directory for built objects.
# This makes sure that the dynamic library goes into the build directory automatically.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")

# This assumes the SDL source is available in vendored/SDL
add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL)

# This assumes the SDL_ttf source is available in vendored/SDL_ttf
add_subdirectory(vendored/SDL_ttf EXCLUDE_FROM_ALL)

#find_package(SDL3)
#find_package(SDL3_ttf)
target_link_libraries(app PRIVATE SDL3_ttf::SDL3_ttf SDL3::SDL3)
git clone https://github.com/libsdl.org/SDL vendored/SDL
git clone https://github.com/libsdl.org/SDL_ttf vendored/SDL_ttf
cd SDL_ttf
git submodule update --init --recursive
cd ../SDL
git bisect start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants