From b8481369f7209804d70220a29ba2efbd6171d7a9 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 22 Nov 2016 12:15:58 +0100 Subject: Reviewed some lua examples and added new ones --- examples/text_ttf_loading.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'examples/text_ttf_loading.c') diff --git a/examples/text_ttf_loading.c b/examples/text_ttf_loading.c index b614023f..918209dd 100644 --- a/examples/text_ttf_loading.c +++ b/examples/text_ttf_loading.c @@ -20,17 +20,22 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading"); - const char msg1[50] = "TTF SpriteFont"; + const char msg[50] = "TTF SpriteFont"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // TTF SpriteFont loading with custom generation parameters SpriteFont font = LoadSpriteFontTTF("resources/fonts/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); float fontSize = font.size; Vector2 fontPosition = { 40, screenHeight/2 + 50 }; Vector2 textSize; + SetTextureFilter(font.texture, FILTER_POINT); int currentFontFilter = 0; // FILTER_POINT int count = 0; @@ -59,12 +64,12 @@ int main() } else if (IsKeyPressed(KEY_THREE)) { - // NOTE: Trilinear filter not supported in font because there are not mipmap levels + // NOTE: Trilinear filter won't be noticed on 2D drawing SetTextureFilter(font.texture, FILTER_TRILINEAR); - //currentFontFilter = 2; + currentFontFilter = 2; } - textSize = MeasureTextEx(font, msg1, fontSize, 0); + textSize = MeasureTextEx(font, msg, fontSize, 0); if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10; else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10; @@ -94,7 +99,7 @@ int main() 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, msg1, fontPosition, fontSize, 0, BLACK); + 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); @@ -106,6 +111,7 @@ int main() 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(); //---------------------------------------------------------------------------------- -- cgit v1.2.3