diff --git a/examples/Makefile b/examples/Makefile index 3e1844fc3..8c39b72a7 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -660,6 +660,7 @@ TEXT = \ text/text_font_loading \ text/text_font_sdf \ text/text_font_spritefont \ + text/text_font_size_metric \ text/text_format_text \ text/text_inline_styling \ text/text_input_box \ diff --git a/examples/text/resources/Autography.ttf b/examples/text/resources/Autography.ttf new file mode 100644 index 000000000..6e76db2d1 Binary files /dev/null and b/examples/text/resources/Autography.ttf differ diff --git a/examples/text/resources/Comic Sans MS.ttf b/examples/text/resources/Comic Sans MS.ttf new file mode 100644 index 000000000..831e3d867 Binary files /dev/null and b/examples/text/resources/Comic Sans MS.ttf differ diff --git a/examples/text/resources/Creator Genius.ttf b/examples/text/resources/Creator Genius.ttf new file mode 100644 index 000000000..42dd360d0 Binary files /dev/null and b/examples/text/resources/Creator Genius.ttf differ diff --git a/examples/text/resources/PixelSimpel.ttf b/examples/text/resources/PixelSimpel.ttf new file mode 100644 index 000000000..9331a37eb Binary files /dev/null and b/examples/text/resources/PixelSimpel.ttf differ diff --git a/examples/text/resources/centurygothic.ttf b/examples/text/resources/centurygothic.ttf new file mode 100644 index 000000000..c60a32412 Binary files /dev/null and b/examples/text/resources/centurygothic.ttf differ diff --git a/examples/text/resources/m5x7.ttf b/examples/text/resources/m5x7.ttf new file mode 100755 index 000000000..2ed774d4d Binary files /dev/null and b/examples/text/resources/m5x7.ttf differ diff --git a/examples/text/resources/m6x11.ttf b/examples/text/resources/m6x11.ttf new file mode 100644 index 000000000..cb2122489 Binary files /dev/null and b/examples/text/resources/m6x11.ttf differ diff --git a/examples/text/resources/monogram.ttf b/examples/text/resources/monogram.ttf new file mode 100755 index 000000000..aceaebab7 Binary files /dev/null and b/examples/text/resources/monogram.ttf differ diff --git a/examples/text/text_font_size_metric.c b/examples/text/text_font_size_metric.c new file mode 100644 index 000000000..a4cee442a --- /dev/null +++ b/examples/text/text_font_size_metric.c @@ -0,0 +1,74 @@ +#include "raylib.h" +#include + +int main(void) { + + InitWindow(960, 540, "raylib [text] example - font scaling metrics"); + + // Some fonts need to be loaded using the Em Box scaling metric. + // Loading this font with the default font size metric and then drawing it to a render texture with a point filter can cause blurry rendering + SetFontSizeMetric(FONT_SIZE_METRIC_EM_BOX); + + Font fontm5x7 = LoadFontEx("text/resources/m5x7.ttf", 16, NULL, 0); + Font fontm6x11 = LoadFontEx("text/resources/m6x11.ttf", 16, NULL, 0); + Font fontMonogram = LoadFontEx("text/resources/monogram.ttf", 16, NULL, 0); + + // Other fonts can use the default Ascent scaling metric. + // (this was the default metric, but didn't work with some pixel fonts, so now you have the option to choose which metric to use for your font) + SetFontSizeMetric(FONT_SIZE_METRIC_ASCENT); + Font fontCenturyGothic = LoadFontEx("text/resources/centurygothic.ttf", 32, NULL, 0); + Font fontComicSansMS = LoadFontEx("text/resources/Comic Sans MS.ttf", 32, NULL, 0); + Font fontAutography = LoadFontEx("text/resources/Autography.ttf", 64, NULL, 0); + + // Set up Render Texture + RenderTexture2D target = LoadRenderTexture(480, 270); + SetTextureFilter(target.texture, TEXTURE_FILTER_POINT); + + // Application loop + SetTargetFPS(60); + + while(!WindowShouldClose()) { + + BeginTextureMode(target); + ClearBackground(BLACK); + + // Render fonts with Em Box scaling metric + DrawTextEx(fontm5x7, "m5x7", (Vector2) { 50, 50 }, 32.0f, 2, WHITE); + DrawTextEx(fontm6x11, "m6x11", (Vector2) { 50, 100 }, 32.0f, 2, WHITE); + DrawTextEx(fontMonogram, "monogram", (Vector2) { 50, 150 }, 32.0f, 2, WHITE); + + // Render fonts with Ascent scaling metric + DrawTextEx(fontCenturyGothic, "Century Gothic", (Vector2) { 200, 50 }, 32.0f, 2, WHITE); + DrawTextEx(fontComicSansMS, "Comic Sans MS", (Vector2) { 200, 100 }, 32.0f, 2, WHITE); + DrawTextEx(fontAutography, "Autography", (Vector2) { 200, 150 }, 64.0f, 2, WHITE); + + EndTextureMode(); + + BeginDrawing(); + ClearBackground(BLACK); + DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE); + + DrawLine(180, 0, 180, 250, WHITE); + DrawLine(50, 30, 450, 30, WHITE); + + DrawText("Em Box", 50, 0, 32, WHITE); + DrawText("Ascent", 200, 0, 32, WHITE); + + EndDrawing(); + } + + // Cleanup + UnloadFont(fontm5x7); + UnloadFont(fontm6x11); + UnloadFont(fontMonogram); + + UnloadFont(fontCenturyGothic); + UnloadFont(fontComicSansMS); + UnloadFont(fontAutography); + + UnloadRenderTexture(target); + + CloseWindow(); + + return 0; +}