summaryrefslogtreecommitdiffhomepage
path: root/examples/text
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-14 15:34:23 +0200
committerRay <[email protected]>2019-05-14 15:34:23 +0200
commit424d3ca8d9c5d612606444b2a2099cfad37f1888 (patch)
tree873e8ec9dbd5965d828ed450a8c12feafe714597 /examples/text
parent2edec8ae288ba70630021b330fe61c9005bc03d9 (diff)
downloadraylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.tar.gz
raylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.zip
examples review
Redesigns, deletes and renames Also noted authors propertly on contributed examples
Diffstat (limited to 'examples/text')
-rw-r--r--examples/text/text_bmfont_ttf.c40
-rw-r--r--examples/text/text_bmfont_ttf.pngbin19542 -> 20086 bytes
-rw-r--r--examples/text/text_bmfont_unordered.c65
-rw-r--r--examples/text/text_bmfont_unordered.pngbin18713 -> 0 bytes
-rw-r--r--examples/text/text_rectangle_bounds.c (renamed from examples/text/text_draw_inside_rectangle.c)6
-rw-r--r--examples/text/text_rectangle_bounds.png (renamed from examples/text/text_draw_inside_rectangle.png)bin17844 -> 17844 bytes
-rw-r--r--examples/text/text_unicode.c2
7 files changed, 32 insertions, 81 deletions
diff --git a/examples/text/text_bmfont_ttf.c b/examples/text/text_bmfont_ttf.c
index f71f5ddb..ca26b2cf 100644
--- a/examples/text/text_bmfont_ttf.c
+++ b/examples/text/text_bmfont_ttf.c
@@ -20,17 +20,20 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");
- const char msgBm[64] = "THIS IS AN AngelCode SPRITE FONT";
- const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF";
+ // Define characters to draw
+ // NOTE: raylib supports UTF-8 encoding, following list is actually codified as UTF8 internally
+ const char msg[256] = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI\nJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmn\nopqrstuvwxyz{|}~¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓ\nÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷\nøùúûüýþÿ";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
- Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode)
- Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font
-
- Vector2 fontPosition;
-
- fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2;
- fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80;
+
+ // BMFont (AngelCode) : Font data and image atlas have been generated using external program
+ Font fontBm = LoadFont("resources/pixantiqua.fnt");
+
+ // TTF font : Font data and atlas are generated directly from TTF
+ // NOTE: We define a font base size of 32 pixels tall and up-to 250 characters
+ Font fontTtf = LoadFontEx("resources/pixantiqua.ttf", 32, 0, 250);
+
+ bool useTtf = false;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -40,7 +43,8 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update variables here...
+ if (IsKeyDown(KEY_SPACE)) useTtf = true;
+ else useTtf = false;
//----------------------------------------------------------------------------------
// Draw
@@ -48,9 +52,19 @@ int main()
BeginDrawing();
ClearBackground(RAYWHITE);
-
- DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON);
- DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.baseSize*0.8f, 2, LIME);
+
+ DrawText("Press SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY);
+
+ if (!useTtf)
+ {
+ DrawTextEx(fontBm, msg, (Vector2){ 20.0f, 100.0f }, fontBm.baseSize, 2, MAROON);
+ DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY);
+ }
+ else
+ {
+ DrawTextEx(fontTtf, msg, (Vector2){ 20.0f, 100.0f }, fontTtf.baseSize, 2, LIME);
+ DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY);
+ }
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/text/text_bmfont_ttf.png b/examples/text/text_bmfont_ttf.png
index 8305d36b..a99027ad 100644
--- a/examples/text/text_bmfont_ttf.png
+++ b/examples/text/text_bmfont_ttf.png
Binary files differ
diff --git a/examples/text/text_bmfont_unordered.c b/examples/text/text_bmfont_unordered.c
deleted file mode 100644
index a5147619..00000000
--- a/examples/text/text_bmfont_unordered.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [text] example - BMFont unordered chars loading and drawing
-*
-* This example has been created using raylib 1.4 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2016 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
-
- InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing");
-
- // NOTE: Using chars outside the [32..127] limits!
- // NOTE: If a character is not found in the font, it just renders a space
- const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
-
- // NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
- Font font = LoadFont("resources/pixantiqua.fnt"); // BMFont (AngelCode)
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- // TODO: Update variables here...
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY);
- DrawText(FormatText("Font base size: %i", font.baseSize), 40, 80, 20, GRAY);
- DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY);
-
- DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.baseSize, 0, MAROON);
-
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadFont(font); // AngelCode Font unloading
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-} \ No newline at end of file
diff --git a/examples/text/text_bmfont_unordered.png b/examples/text/text_bmfont_unordered.png
deleted file mode 100644
index c6767567..00000000
--- a/examples/text/text_bmfont_unordered.png
+++ /dev/null
Binary files differ
diff --git a/examples/text/text_draw_inside_rectangle.c b/examples/text/text_rectangle_bounds.c
index e60fa5e5..d4cd240a 100644
--- a/examples/text/text_draw_inside_rectangle.c
+++ b/examples/text/text_rectangle_bounds.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2018 Vlad Adrian (@demizdor)
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -37,9 +39,7 @@ int main()
const int maxHeight = screenHeight - 160;
Vector2 lastMouse = { 0, 0 }; // Stores last mouse coordinates
-
Color borderColor = MAROON; // Container border color
-
Font font = GetFontDefault(); // Get default system font
SetTargetFPS(60);
diff --git a/examples/text/text_draw_inside_rectangle.png b/examples/text/text_rectangle_bounds.png
index f46b1096..f46b1096 100644
--- a/examples/text/text_draw_inside_rectangle.png
+++ b/examples/text/text_rectangle_bounds.png
Binary files differ
diff --git a/examples/text/text_unicode.c b/examples/text/text_unicode.c
index b6c6db30..6b456a75 100644
--- a/examples/text/text_unicode.c
+++ b/examples/text/text_unicode.c
@@ -5,6 +5,8 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
* Copyright (c) 2019 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/