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

Re-added solid text rendering #424

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Several functions have been renamed. We have provided a handy semantic patch to

In general we have switched to using UTF8 in the API. Functions which had 3 variants, for Latin-1, UTF-8, and UCS2, now accept UTF-8 text. In addition, those functions now have an optional length parameter which allows you to render substrings.

The solid color rendering functions have been removed in favor of the higher quality shaded and blended functions.

The alpha in background colors is now transparent if it's equal to 0.

The following functions have been renamed:
Expand All @@ -58,12 +56,15 @@ The following functions have been renamed:
* TTF_RenderGlyph32_Blended() => TTF_RenderGlyph_Blended()
* TTF_RenderGlyph32_LCD() => TTF_RenderGlyph_LCD()
* TTF_RenderGlyph32_Shaded() => TTF_RenderGlyph_Shaded()
* TTF_RenderGlyph32_Solid() => TTF_RenderGlyph_Solid()
* TTF_RenderUTF8_Blended() => TTF_RenderText_Blended()
* TTF_RenderUTF8_Blended_Wrapped() => TTF_RenderText_Blended_Wrapped()
* TTF_RenderUTF8_LCD() => TTF_RenderText_LCD()
* TTF_RenderUTF8_LCD_Wrapped() => TTF_RenderText_LCD_Wrapped()
* TTF_RenderUTF8_Shaded() => TTF_RenderText_Shaded()
* TTF_RenderUTF8_Shaded_Wrapped() => TTF_RenderText_Shaded_Wrapped()
* TTF_RenderUTF8_Solid() => TTF_RenderText_Solid()
* TTF_RenderUTF8_Solid_Wrapped() => TTF_RenderText_Solid_Wrapped()
* TTF_SetFontScriptName() => TTF_SetFontScript()
* TTF_SetFontWrappedAlign() => TTF_SetFontWrapAlignment()
* TTF_SizeText() => TTF_GetTextSize()
Expand All @@ -81,7 +82,6 @@ The following functions have been removed:
* TTF_OpenFontIndexDPI() - replaced with TTF_OpenFontWithProperties()
* TTF_OpenFontIndexDPIIO() - replaced with TTF_OpenFontWithProperties()
* TTF_OpenFontIndexIO() - replaced with TTF_OpenFontWithProperties()
* TTF_RenderGlyph32_Solid()
* TTF_RenderGlyph_Solid()
* TTF_RenderText_Solid()
* TTF_RenderText_Solid_Wrapped()
Expand All @@ -93,8 +93,6 @@ The following functions have been removed:
* TTF_RenderUNICODE_Shaded_Wrapped()
* TTF_RenderUNICODE_Solid()
* TTF_RenderUNICODE_Solid_Wrapped()
* TTF_RenderUTF8_Solid()
* TTF_RenderUTF8_Solid_Wrapped()
* TTF_SizeUNICODE()

The following symbols have been renamed:
Expand Down
15 changes: 13 additions & 2 deletions examples/showfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


#define TTF_SHOWFONT_USAGE \
"Usage: %s [-textengine surface|renderer] [-shaded] [-blended] [-wrapped] [-b] [-i] [-u] [-s] [-outline size] [-hintlight|-hintmono|-hintnone] [-nokerning] [-wrap] [-align left|center|right] [-fgcol r,g,b,a] [-bgcol r,g,b,a] [-editbox] <font>.ttf [ptsize] [text]\n"
"Usage: %s [-textengine surface|renderer] [-solid] [-shaded] [-blended] [-wrapped] [-b] [-i] [-u] [-s] [-outline size] [-hintlight|-hintmono|-hintnone] [-nokerning] [-wrap] [-align left|center|right] [-fgcol r,g,b,a] [-bgcol r,g,b,a] [-editbox] <font>.ttf [ptsize] [text]\n"

typedef enum
{
Expand All @@ -51,6 +51,7 @@ typedef enum

typedef enum
{
TextRenderSolid,
TextRenderShaded,
TextRenderBlended
} TextRenderMethod;
Expand Down Expand Up @@ -100,7 +101,7 @@ static void DrawScene(Scene *scene)
case TextEngineSurface:
/* Flush the renderer so we can draw directly to the window surface */
SDL_FlushRenderer(renderer);
TTF_DrawSurfaceText(scene->caption, scene->captionRect.w, scene->captionRect.h, scene->window_surface);
TTF_DrawSurfaceText(scene->caption, scene->captionRect.x, scene->captionRect.y, scene->window_surface);
break;
case TextEngineRenderer:
TTF_DrawRendererText(scene->caption, (float)scene->captionRect.x, (float)scene->captionRect.y);
Expand Down Expand Up @@ -311,6 +312,9 @@ int main(int argc, char *argv[])
return(1);
}
} else
if (SDL_strcmp(argv[i], "-solid") == 0) {
rendermethod = TextRenderSolid;
} else
if (SDL_strcmp(argv[i], "-shaded") == 0) {
rendermethod = TextRenderShaded;
} else
Expand Down Expand Up @@ -511,6 +515,13 @@ int main(int argc, char *argv[])
message = DEFAULT_TEXT;
}
switch (rendermethod) {
case TextRenderSolid:
if (wrap) {
text = TTF_RenderText_Solid_Wrapped(font, message, 0, *forecol, 0);
} else {
text = TTF_RenderText_Solid(font, message, 0, *forecol);
}
break;
case TextRenderShaded:
if (wrap) {
text = TTF_RenderText_Shaded_Wrapped(font, message, 0, *forecol, *backcol, 0);
Expand Down
40 changes: 25 additions & 15 deletions examples/testapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void help(void)
SDL_Log("t : ticks elapsed for 50 rendering");
SDL_Log("d : display normal texture, no screen update, stream texture ");
SDL_Log("r : start/stop random test");
SDL_Log("m : render mode Blended/Shaded");
SDL_Log("m : render mode Solid/Blended/Shaded");
SDL_Log("x : text engine None/Surface/Renderer");
SDL_Log("n : change direction");
SDL_Log("9/0 : -/+ alpha color fg");
Expand Down Expand Up @@ -191,10 +191,10 @@ static int print_elapsed_ticks = 0;
static int update_screen_mode = 0;
static int save_to_bmp = 0;

/* RENDER_BLENDED = 0, RENDER_SHADED = 1, RENDER_LCD = 2 */
/* RENDER_SOLID = 0, RENDER_BLENDED = 1, RENDER_SHADED = 2, RENDER_LCD = 3 } */
static int render_mode = -1;
static int render_mode_overwrite;
static const char *render_mode_desc[] = { "Blended", "Shaded", "LCD" };
static const char *render_mode_desc[] = { "Solid", "Blended", "Shaded", "LCD" };
static const int render_mode_count = SDL_arraysize(render_mode_desc);

static int textengine_mode = 0;
Expand Down Expand Up @@ -698,6 +698,10 @@ int main(void)
seed=1641805930; replay=1; font_style=9; kerning=1; sdf=1; wrap=0; wrap_size=661; w_align=2; outline=0; curr_size=20; render_mode=3; curr_str=14; curr_font=1777; hinting=1; fg_alpha=65; // light LCD
#endif

//seed=1673390190; replay=1; font_style=12; kerning=0; sdf=1; wrap=0; wrap_size=91; w_align=0; outline=0; curr_size=16; render_mode=0; curr_str=14; curr_font=1288; hinting=0; fg_alpha=77; // none Solid

//seed=1673390190; replay=1; font_style=12; kerning=0; sdf=0; wrap=0; wrap_size=91; w_align=0; outline=0; curr_size=30; render_mode=1; curr_str=14; curr_font=1288; hinting=0; fg_alpha=77; // none Solid

//seed=1673390190; replay=1; font_style=9; kerning=1; sdf=0; wrap=1; wrap_size=94; w_align=2; outline=7; curr_size=42; render_mode=1; curr_str=75; curr_font=1997; hinting=1; fg_alpha=90; // light Blended

if (replay) {
Expand Down Expand Up @@ -957,15 +961,17 @@ int main(void)

if (textengine_mode == 0) {

switch (render_mode)
{
switch (render_mode) {
case 0:
text_surface = TTF_RenderText_Blended(font, text, 0, textcol);
text_surface = TTF_RenderText_Solid(font, text, 0, textcol);
break;
case 1:
text_surface = TTF_RenderText_Shaded(font, text, 0, textcol, boardcol);
text_surface = TTF_RenderText_Blended(font, text, 0, textcol);
break;
case 2:
text_surface = TTF_RenderText_Shaded(font, text, 0, textcol, boardcol);
break;
case 3:
#if defined(HAVE_LCD)
text_surface = TTF_RenderText_LCD(font, text, 0, textcol, boardcol);
#else
Expand Down Expand Up @@ -996,15 +1002,17 @@ int main(void)
}

if (textengine_mode == 0) {
switch (render_mode)
{
switch (render_mode) {
case 0:
text_surface = TTF_RenderText_Blended(font, text, 0, textcol);
text_surface = TTF_RenderText_Solid(font, text, 0, textcol);
break;
case 1:
text_surface = TTF_RenderText_Shaded(font, text, 0, textcol, boardcol);
text_surface = TTF_RenderText_Blended(font, text, 0, textcol);
break;
case 2:
text_surface = TTF_RenderText_Shaded(font, text, 0, textcol, boardcol);
break;
case 3:
#if defined(HAVE_LCD)
text_surface = TTF_RenderText_LCD(font, text, 0, textcol, boardcol);
#else
Expand Down Expand Up @@ -1047,15 +1055,17 @@ int main(void)
}

if (textengine_mode == 0) {
switch (render_mode)
{
switch (render_mode) {
case 0:
text_surface = TTF_RenderText_Blended_Wrapped(font, text, 0, textcol, wrap_size);
text_surface = TTF_RenderText_Solid_Wrapped(font, text, 0, textcol, wrap_size);
break;
case 1:
text_surface = TTF_RenderText_Shaded_Wrapped(font, text, 0, textcol, boardcol, wrap_size);
text_surface = TTF_RenderText_Blended_Wrapped(font, text, 0, textcol, wrap_size);
break;
case 2:
text_surface = TTF_RenderText_Shaded_Wrapped(font, text, 0, textcol, boardcol, wrap_size);
break;
case 3:
#if defined(HAVE_LCD)
text_surface = TTF_RenderText_LCD_Wrapped(font, text, 0, textcol, boardcol, wrap_size);
#else
Expand Down
Loading
Loading