-
Notifications
You must be signed in to change notification settings - Fork 152
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
The word wrapping may disagree between outlined and non-outlined text in Surface Engine #526
Comments
Can you post a minimal example with fonts, sizes and widths? |
Also, it makes sense that this would happen - outlined text is larger and will not fit in the same space. |
Hi! Here is an example! And yeah, tho it makes sense there's no way to counteract it (by saving the wrap previously based on the outline version, or by faking the outline size on the inner text so it wraps the same, etc). #include <SDL3/SDL.h>
#include <SDL3/SDL_ttf.h>
int main(int argc, char* argv[]) {
//Setup
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
//More Setup
SDL_Window* window = SDL_CreateWindow("Outlined Text", 800, 600, 0);
SDL_Renderer* renderer = SDL_CreateRenderer(window,NULL);
TTF_Font* font = TTF_OpenFont("RockoUltraFLF.ttf", 68);
//Params
SDL_Color textColor = { 255, 255, 255, 255 };
SDL_Color outline_color = { 255, 0, 0, 255 };
int outline_size = 5;
int wrap_width = 436;
const char* text = "Auribus oculi fideliores sunt";
//Render Outline
TTF_SetFontOutline(font, outline_size);
SDL_Surface* outline = TTF_RenderText_Blended_Wrapped(font, text, 0, outline_color, wrap_width);
//Render Inner
TTF_SetFontOutline(font, 0);
SDL_Surface* inner = TTF_RenderText_Blended_Wrapped(font, text, 0, textColor, wrap_width);
//Blit Together
SDL_Rect rect = { outline_size, outline_size, inner->w, inner->h };
SDL_SetSurfaceBlendMode(inner, SDL_BLENDMODE_BLEND);
SDL_BlitSurface(inner, NULL, outline, &rect);
//Create Texture
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, outline);
SDL_DestroySurface(outline);
SDL_DestroySurface(inner);
//Display
SDL_FRect textRect;
textRect.x =100;
textRect.y = 100;
textRect.w = (float)textTexture->w;
textRect.h = (float)textTexture->h;
SDL_Event event;
bool running = true;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_QUIT) {
running = false;
}
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderTexture(renderer, textTexture, NULL, &textRect);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(textTexture);
TTF_CloseFont(font);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
TTF_Quit();
SDL_Quit();
return 0;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The word wrapping may disagree between outlined and non-outlined text in Surface Engine, causing a misalignment between the outline and the rendered text when blending, as demonstrated below:
Happens on the latest commit to this point 5208d1c
I couldn't pinpoint if there's an exact case for this to happen, it just happens with some combinations of wrap widths and font+outline sizes, doesn't matter the font you are using.
The text was updated successfully, but these errors were encountered: