-
Notifications
You must be signed in to change notification settings - Fork 151
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
Comments
Can you provide a link to your example and the fonts you used? |
My steps: Setting up SDL3_ttf 3.1.1 I have copied 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) |
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. |
I will try to build SDL_ttf with MinGW and Emscripten and will write about the result later. |
It works for me: TTF_Font *font = TTF_OpenFont("C:/Windows/Fonts/arial.ttf", 48); Sorry and thank you very much! |
You’re welcome! |
@slouken hello! Could you try to reproduce the following steps on the video? sdl-does-not-show-text.mp4SDL 3.2.6 was downloaded from Releases. It is VS version. |
Does this also happen with latest SDL3_TTF 3.2.0? The minimum required SDL3 version is not tested at runtime. Maybe we should? |
The same for SDL3_ttf.dll 3.2.0 and SDL.dll 3.2.8 |
Source: text-sdl3-ttf.zip |
You don't check the return value of TTF_OpenFont(), are you sure the font is being loaded correctly? |
On my system both of the DLLs you provide work. |
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:
|
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.
The text was updated successfully, but these errors were encountered: