diff options
| author | raysan5 <raysan5@gmail.com> | 2016-02-11 12:26:45 +0100 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2016-02-11 12:26:45 +0100 |
| commit | 54c7fa491ef285838a64a8ee015de888c3d24a75 (patch) | |
| tree | d2e192c9485a05793e072145719bfd4d8d47b68c /examples/text_bmfont_ttf.c | |
| parent | c69ce1d7504b94108721403c867bddbf50d7b890 (diff) | |
| download | raylib-54c7fa491ef285838a64a8ee015de888c3d24a75.tar.gz raylib-54c7fa491ef285838a64a8ee015de888c3d24a75.zip | |
Added 6 new examples
Diffstat (limited to 'examples/text_bmfont_ttf.c')
| -rw-r--r-- | examples/text_bmfont_ttf.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/text_bmfont_ttf.c b/examples/text_bmfont_ttf.c new file mode 100644 index 00000000..caece548 --- /dev/null +++ b/examples/text_bmfont_ttf.c @@ -0,0 +1,68 @@ +/******************************************************************************************* +* +* raylib [text] example - BMFont and TTF SpriteFonts loading +* +* 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 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"; + + // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) + SpriteFont fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt"); // BMFont (AngelCode) + SpriteFont fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf"); // TTF font + + Vector2 fontPosition; + + fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2; + fontPosition.y = screenHeight/2 - fontBm.size/2 - 80; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update variables here... + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON); + DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.size*0.8f, 2, LIME); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadSpriteFont(fontBm); // AngelCode SpriteFont unloading + UnloadSpriteFont(fontTtf); // TTF SpriteFont unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file |
