diff options
| author | Ray <[email protected]> | 2019-05-20 16:36:42 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-05-20 16:36:42 +0200 |
| commit | b525039e0ab8bcaa2fd6bde34c72a6405f88ae49 (patch) | |
| tree | 08f1c79bfe693643564ed78202c9474b7eb83a79 /examples/text/text_ttf_loading.c | |
| parent | a43a7980a30a52462956b23f2473e8ef8f38d1fb (diff) | |
| download | raylib-b525039e0ab8bcaa2fd6bde34c72a6405f88ae49.tar.gz raylib-b525039e0ab8bcaa2fd6bde34c72a6405f88ae49.zip | |
Review ALL examples
Diffstat (limited to 'examples/text/text_ttf_loading.c')
| -rw-r--r-- | examples/text/text_ttf_loading.c | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/examples/text/text_ttf_loading.c b/examples/text/text_ttf_loading.c index 0e964ebd..cc59417d 100644 --- a/examples/text/text_ttf_loading.c +++ b/examples/text/text_ttf_loading.c @@ -11,22 +11,22 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading"); - + const char msg[50] = "TTF Font"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) - + // TTF Font loading with custom generation parameters Font font = LoadFontEx("resources/KAISG.ttf", 96, 0, 0); - + // Generate mipmap levels to use trilinear filtering // NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR GenTextureMipmaps(&font.texture); @@ -35,25 +35,20 @@ int main() Vector2 fontPosition = { 40, screenHeight/2 - 80 }; Vector2 textSize; + // Setup texture scaling filter SetTextureFilter(font.texture, FILTER_POINT); int currentFontFilter = 0; // FILTER_POINT - - // NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX -#if defined(PLATFORM_DESKTOP) - int count = 0; - char **droppedFiles; -#endif - - SetTargetFPS(60); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- fontSize += GetMouseWheelMove()*4.0f; - + // Choose font texture filter method if (IsKeyPressed(KEY_ONE)) { @@ -71,18 +66,18 @@ int main() SetTextureFilter(font.texture, FILTER_TRILINEAR); currentFontFilter = 2; } - + textSize = MeasureTextEx(font, msg, fontSize, 0); - + if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10; else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10; - -#if defined(PLATFORM_DESKTOP) + // Load a dropped TTF file dynamically (at current fontSize) if (IsFileDropped()) { - droppedFiles = GetDroppedFiles(&count); - + int count = 0; + char **droppedFiles = GetDroppedFiles(&count); + if (count == 1) // Only support one ttf file dropped { UnloadFont(font); @@ -90,47 +85,45 @@ int main() ClearDroppedFiles(); } } -#endif //---------------------------------------------------------------------------------- - + // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY); DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY); DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY); DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY); DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK); - + // TODO: It seems texSize measurement is not accurate due to chars offsets... //DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED); - + DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY); DrawText(FormatText("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY); DrawText(FormatText("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY); DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY); - + if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK); else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK); else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK); - + EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- -#if defined(PLATFORM_DESKTOP) ClearDroppedFiles(); // Clear internal buffers -#endif - UnloadFont(font); // Font unloading - + + UnloadFont(font); // Font unloading + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + return 0; }
\ No newline at end of file |
