From 0603e59cae0da924d7fe811b078972e04cdfe1e9 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 18 Nov 2016 14:05:49 +0100 Subject: Review examples and added new ones --- examples/text_ttf_loading.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 examples/text_ttf_loading.c (limited to 'examples/text_ttf_loading.c') diff --git a/examples/text_ttf_loading.c b/examples/text_ttf_loading.c new file mode 100644 index 00000000..1135619e --- /dev/null +++ b/examples/text_ttf_loading.c @@ -0,0 +1,125 @@ +/******************************************************************************************* +* +* raylib [text] example - TTF loading and usage +* +* This example has been created using raylib 1.3.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" +#include + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading"); + + const char msg1[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); + + float fontSize = font.size; + Vector2 fontPosition = { 40, screenHeight/2 + 50 }; + Vector2 textSize; + + int currentFontFilter = 0; // FILTER_POINT + + int count = 0; + char **droppedFiles; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // 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)) + { + SetTextureFilter(font.texture, FILTER_POINT); + currentFontFilter = 0; + } + else if (IsKeyPressed(KEY_TWO)) + { + SetTextureFilter(font.texture, FILTER_BILINEAR); + currentFontFilter = 1; + } + else if (IsKeyPressed(KEY_THREE)) + { + // NOTE: Trilinear filter not supported in font because there are not mipmap levels + SetTextureFilter(font.texture, FILTER_TRILINEAR); + //currentFontFilter = 2; + } + + textSize = MeasureTextEx(font, msg1, fontSize, 0); + + if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10; + else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10; + + // Load a dropped TTF file dynamically (at current fontSize) + if (IsFileDropped()) + { + droppedFiles = GetDroppedFiles(&count); + + if (count == 1) // Only support one ttf file dropped + { + UnloadSpriteFont(font); + font = LoadSpriteFontTTF(droppedFiles[0], fontSize, 0, 0); + ClearDroppedFiles(); + } + } + //---------------------------------------------------------------------------------- + + // 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, msg1, 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); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadSpriteFont(font); // SpriteFont unloading + + ClearDroppedFiles(); // Clear internal buffers + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file -- cgit v1.2.3 From bdbb1eb90133c882ee84421b1b024b286a76d5ce Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 21 Nov 2016 19:49:54 +0100 Subject: Added new text sample: text_bmfont_unordered BMFont loading has been improved to support unordered chars and extended characters (up to 255) --- examples/Makefile | 5 + examples/resources/fonts/pixantiqua.fnt | 188 ++++++++++++++++++++++++++++++ examples/resources/fonts/pixantiqua_0.png | Bin 0 -> 4531 bytes examples/text_bmfont_unordered.c | 65 +++++++++++ examples/text_bmfont_unordered.png | Bin 0 -> 18713 bytes examples/text_ttf_loading.c | 1 - 6 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 examples/resources/fonts/pixantiqua.fnt create mode 100644 examples/resources/fonts/pixantiqua_0.png create mode 100644 examples/text_bmfont_unordered.c create mode 100644 examples/text_bmfont_unordered.png (limited to 'examples/text_ttf_loading.c') diff --git a/examples/Makefile b/examples/Makefile index da29e915..2cb75ff9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -229,6 +229,7 @@ EXAMPLES = \ text_font_select \ text_writing_anim \ text_ttf_loading \ + text_bmfont_unordered \ models_geometric_shapes \ models_box_collisions \ models_billboard \ @@ -418,6 +419,10 @@ text_writing_anim: text_writing_anim.c text_ttf_loading: text_ttf_loading.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) +# compile [text] example - text bmfont unordered +text_bmfont_unordered: text_bmfont_unordered.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + # compile [models] example - basic geometric 3d shapes models_geometric_shapes: models_geometric_shapes.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) diff --git a/examples/resources/fonts/pixantiqua.fnt b/examples/resources/fonts/pixantiqua.fnt new file mode 100644 index 00000000..971b9b0b --- /dev/null +++ b/examples/resources/fonts/pixantiqua.fnt @@ -0,0 +1,188 @@ +info face="PixAntiqua" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=2,2,2,2 spacing=2,2 outline=0 +common lineHeight=32 base=27 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4 +page id=0 file="pixantiqua_0.png" +chars count=184 +char id=32 x=9 y=304 width=7 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=33 x=391 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=34 x=240 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=35 x=468 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=36 x=152 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=37 x=176 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=38 x=303 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=39 x=495 y=266 width=8 height=36 xoffset=-3 yoffset=-2 xadvance=5 page=0 chnl=15 +char id=40 x=256 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=199 x=432 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=200 x=126 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=201 x=147 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=202 x=288 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=203 x=189 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=204 x=468 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=205 x=486 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=206 x=0 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=207 x=72 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=208 x=329 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=209 x=277 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=210 x=182 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=211 x=26 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=41 x=272 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=42 x=288 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=43 x=414 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=44 x=378 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=45 x=414 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=46 x=443 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=47 x=392 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=48 x=485 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=49 x=450 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=50 x=21 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=51 x=42 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=59 x=456 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=60 x=168 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=61 x=309 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=62 x=336 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=63 x=315 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=64 x=364 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=65 x=390 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=66 x=120 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=67 x=144 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=68 x=168 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=69 x=294 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=52 x=488 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=53 x=63 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=54 x=24 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=55 x=48 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=56 x=72 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=57 x=96 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=58 x=404 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=70 x=252 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=71 x=192 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=72 x=78 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=78 x=78 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=79 x=355 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=80 x=264 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=81 x=381 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=82 x=288 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=83 x=312 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=91 x=144 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=92 x=108 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=93 x=304 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=94 x=34 y=0 width=32 height=36 xoffset=-3 yoffset=-2 xadvance=29 page=0 chnl=15 +char id=95 x=231 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=96 x=442 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=97 x=408 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=98 x=432 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=99 x=210 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=84 x=336 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=85 x=360 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=86 x=0 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=87 x=68 y=0 width=30 height=36 xoffset=-3 yoffset=-2 xadvance=27 page=0 chnl=15 +char id=88 x=26 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=89 x=384 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=90 x=84 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=100 x=456 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=101 x=480 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=102 x=54 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=103 x=0 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=104 x=24 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=105 x=469 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=106 x=18 y=266 width=16 height=36 xoffset=-8 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=107 x=48 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=108 x=417 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=109 x=161 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=110 x=72 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=111 x=96 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=117 x=192 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=118 x=216 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=119 x=248 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=120 x=240 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=121 x=264 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=122 x=288 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=123 x=432 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=124 x=365 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=125 x=378 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=126 x=393 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=127 x=132 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=160 x=0 y=304 width=7 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=161 x=352 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=162 x=351 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=163 x=336 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=165 x=360 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=167 x=384 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=169 x=433 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=170 x=224 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=171 x=105 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=172 x=0 y=0 width=32 height=36 xoffset=-3 yoffset=-2 xadvance=29 page=0 chnl=15 +char id=173 x=494 y=38 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=174 x=52 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=175 x=52 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=176 x=126 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=177 x=435 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=178 x=320 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=179 x=336 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=181 x=459 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=112 x=120 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=113 x=144 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=114 x=396 y=228 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=115 x=168 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=116 x=36 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=182 x=408 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=183 x=498 y=190 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=185 x=192 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=186 x=208 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=187 x=477 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=191 x=456 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=192 x=407 y=0 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=193 x=234 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=194 x=416 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=195 x=156 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=196 x=130 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=197 x=104 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=198 x=190 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=212 x=0 y=76 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=213 x=338 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=214 x=312 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=215 x=357 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=216 x=286 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=217 x=456 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=218 x=480 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=219 x=0 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=220 x=24 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=221 x=48 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=222 x=260 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=223 x=72 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=224 x=96 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=225 x=120 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=226 x=144 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=227 x=168 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=228 x=192 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=229 x=216 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=230 x=219 y=0 width=27 height=36 xoffset=-3 yoffset=-2 xadvance=24 page=0 chnl=15 +char id=231 x=372 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=73 x=90 y=266 width=16 height=36 xoffset=-3 yoffset=-2 xadvance=13 page=0 chnl=15 +char id=74 x=216 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=75 x=240 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=76 x=273 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=77 x=100 y=0 width=30 height=36 xoffset=-3 yoffset=-2 xadvance=27 page=0 chnl=15 +char id=232 x=312 y=152 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=233 x=240 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=234 x=264 y=190 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=235 x=104 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=236 x=430 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=237 x=482 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=238 x=160 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=11 page=0 chnl=15 +char id=239 x=176 y=266 width=14 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 +char id=240 x=128 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=241 x=200 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=242 x=224 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=243 x=248 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=244 x=272 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=245 x=296 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=246 x=320 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=247 x=330 y=190 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=248 x=208 y=38 width=24 height=36 xoffset=-3 yoffset=-2 xadvance=21 page=0 chnl=15 +char id=249 x=344 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=250 x=368 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=251 x=416 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=252 x=440 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=253 x=464 y=76 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 +char id=254 x=0 y=228 width=19 height=36 xoffset=-3 yoffset=-2 xadvance=16 page=0 chnl=15 +char id=255 x=0 y=114 width=22 height=36 xoffset=-3 yoffset=-2 xadvance=19 page=0 chnl=15 diff --git a/examples/resources/fonts/pixantiqua_0.png b/examples/resources/fonts/pixantiqua_0.png new file mode 100644 index 00000000..2aa2870f Binary files /dev/null and b/examples/resources/fonts/pixantiqua_0.png differ diff --git a/examples/text_bmfont_unordered.c b/examples/text_bmfont_unordered.c new file mode 100644 index 00000000..b29c5f8b --- /dev/null +++ b/examples/text_bmfont_unordered.c @@ -0,0 +1,65 @@ +/******************************************************************************************* +* +* 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) + SpriteFont font = LoadSpriteFont("resources/fonts/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.size), 40, 80, 20, GRAY); + DrawText(FormatText("Font chars number: %i", font.numChars), 40, 110, 20, GRAY); + + DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.size, 0, MAROON); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadSpriteFont(font); // AngelCode SpriteFont unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/text_bmfont_unordered.png b/examples/text_bmfont_unordered.png new file mode 100644 index 00000000..c6767567 Binary files /dev/null and b/examples/text_bmfont_unordered.png differ diff --git a/examples/text_ttf_loading.c b/examples/text_ttf_loading.c index 1135619e..b614023f 100644 --- a/examples/text_ttf_loading.c +++ b/examples/text_ttf_loading.c @@ -10,7 +10,6 @@ ********************************************************************************************/ #include "raylib.h" -#include int main() { -- cgit v1.2.3 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/audio_module_playing.lua | 31 ++----- examples/core_3d_camera_first_person.lua | 11 ++- examples/core_3d_camera_free.lua | 11 +-- examples/core_3d_picking.lua | 8 +- examples/core_input_gamepad.lua | 134 +++++++++++++++++++++++++++---- examples/core_world_screen.lua | 7 +- examples/models_billboard.lua | 9 +-- examples/models_cubicmap.lua | 8 +- examples/models_heightmap.lua | 7 +- examples/rlua_execute_file.c | 4 +- examples/shaders_custom_uniform.lua | 14 ++-- examples/shaders_model_shader.c | 4 +- examples/shaders_model_shader.lua | 6 +- examples/shaders_postprocessing.lua | 10 +-- examples/shaders_standard_lighting.lua | 10 +-- examples/text_bmfont_unordered.lua | 57 +++++++++++++ examples/text_ttf_loading.c | 16 ++-- examples/text_ttf_loading.lua | 118 +++++++++++++++++++++++++++ src/rlua.h | 77 +++++++++++------- 19 files changed, 402 insertions(+), 140 deletions(-) create mode 100644 examples/text_bmfont_unordered.lua create mode 100644 examples/text_ttf_loading.lua (limited to 'examples/text_ttf_loading.c') diff --git a/examples/audio_module_playing.lua b/examples/audio_module_playing.lua index 3c5ad641..7c675424 100644 --- a/examples/audio_module_playing.lua +++ b/examples/audio_module_playing.lua @@ -37,13 +37,6 @@ for i = MAX_CIRCLES, 1, -1 do circles[i].color = colors[GetRandomValue(1, 14)] end --- Load postprocessing bloom shader -local shader = LoadShader("resources/shaders/glsl330/base.vs", - "resources/shaders/glsl330/bloom.fs") - --- Create a RenderTexture2D to be used for render to texture -local target = LoadRenderTexture(screenWidth, screenHeight) - local xm = LoadMusicStream("resources/audio/mini1111.xm") PlayMusicStream(xm) @@ -83,22 +76,11 @@ while not WindowShouldClose() do -- Detect window close button or ESC key --------------------------------------------------------------------------------------- BeginDrawing() - ClearBackground(BLACK) - - BeginTextureMode(target) -- Enable drawing to texture - - for i = MAX_CIRCLES, 1, -1 do - DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)) - end - - EndTextureMode() -- End drawing to texture (now we have a texture available for next passes) + ClearBackground(RAYWHITE) - BeginShaderMode(shader) - - -- NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTextureRec(target.texture, Rectangle(0, 0, target.texture.width, -target.texture.height), Vector2(0, 0), WHITE) - - EndShaderMode() + for i = MAX_CIRCLES, 1, -1 do + DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha)) + end -- Draw time bar DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY) @@ -111,10 +93,7 @@ end -- De-Initialization ------------------------------------------------------------------------------------------- -UnloadShader(shader) -- Unload shader -UnloadRenderTexture(target) -- Unload render texture - -UnloadMusicStream(xm) -- Unload music stream buffers from RAM +UnloadMusicStream(xm) -- Unload music stream buffers from RAM CloseAudioDevice() -- Close audio device (music streaming is automatically stopped) diff --git a/examples/core_3d_camera_first_person.lua b/examples/core_3d_camera_first_person.lua index 800c3c2a..22ccdc5c 100644 --- a/examples/core_3d_camera_first_person.lua +++ b/examples/core_3d_camera_first_person.lua @@ -19,7 +19,7 @@ local screenHeight = 450 InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person") -- Define the camera to look into our 3d world (position, target, up vector) -local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 60.0) +local camera = Camera(Vector3(4.0, 2.0, 4.0), Vector3(0.0, 1.8, 0.0), Vector3(0.0, 1.0, 0.0), 60.0) -- Generates some random columns local heights = {} @@ -34,17 +34,16 @@ end local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position -SetCameraMode(CameraMode.FIRST_PERSON) -- Set a first person camera mode -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FIRST_PERSON) -- Set a first person camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera, playerPosition = UpdateCameraPlayer(camera, playerPosition) -- Update camera and player position + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/core_3d_camera_free.lua b/examples/core_3d_camera_free.lua index 244aad6b..57fa7a12 100644 --- a/examples/core_3d_camera_free.lua +++ b/examples/core_3d_camera_free.lua @@ -18,26 +18,23 @@ InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free") -- Define the camera to look into our 3d world local camera = {} -camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position +camera.position = Vector3(10.0, 10.0, 10.0) -- Camera position camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target) camera.fovy = 45.0 -- Camera field-of-view Y local cubePosition = Vector3(0.0, 0.0, 0.0) -SetCameraMode(CameraMode.FREE) -- Set a free camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/core_3d_picking.lua b/examples/core_3d_picking.lua index 1adee67c..230f5756 100644 --- a/examples/core_3d_picking.lua +++ b/examples/core_3d_picking.lua @@ -30,18 +30,16 @@ local ray = Ray(Vector3(0, 0, 0), Vector3(0, 0, 0)) -- Picking line ray local collision = false -SetCameraMode(CameraMode.FREE) -- Set a free camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then -- NOTE: This function is NOT WORKING properly! diff --git a/examples/core_input_gamepad.lua b/examples/core_input_gamepad.lua index 78d9b84e..ade3f00f 100644 --- a/examples/core_input_gamepad.lua +++ b/examples/core_input_gamepad.lua @@ -19,8 +19,8 @@ local screenHeight = 450 InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input") -local ballPosition = Vector2(screenWidth/2, screenHeight/2) -local gamepadMovement = Vector2(0, 0) +local texPs3Pad = LoadTexture("resources/ps3.png") +local texXboxPad = LoadTexture("resources/xbox.png") SetTargetFPS(60) -- Set target frames-per-second ------------------------------------------------------------------------------------------- @@ -29,18 +29,7 @@ SetTargetFPS(60) -- Set target frames-per-second while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then - gamepadMovement.x = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X) - gamepadMovement.y = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y) - - ballPosition.x = ballPosition.x + gamepadMovement.x - ballPosition.y = ballPosition.y - gamepadMovement.y - - if (IsGamepadButtonPressed(GAMEPAD.PLAYER1, GAMEPAD.BUTTON_A)) then - ballPosition.x = screenWidth/2 - ballPosition.y = screenHeight/2 - end - end + -- ... --------------------------------------------------------------------------------------- -- Draw @@ -49,9 +38,117 @@ while not WindowShouldClose() do -- Detect window close button or ESC key ClearBackground(RAYWHITE) - DrawText("move the ball with gamepad", 10, 10, 20, DARKGRAY) + if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then + DrawText(string.format("GP1: %s", GetGamepadName(GAMEPAD.PLAYER1)), 10, 10, 10, BLACK) + + if (IsGamepadName(GAMEPAD.PLAYER1, "Xbox 360 Controller")) then + DrawTexture(texXboxPad, 0, 0, DARKGRAY) + + -- Draw buttons: xbox home + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_HOME)) then DrawCircle(394, 89, 19, RED) end + + -- Draw buttons: basic + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_START)) then DrawCircle(436, 150, 9, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_SELECT)) then DrawCircle(352, 150, 9, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_X)) then DrawCircle(501, 151, 15, BLUE) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_A)) then DrawCircle(536, 187, 15, LIME) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_B)) then DrawCircle(572, 151, 15, MAROON) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_Y)) then DrawCircle(536, 115, 15, GOLD) end + + -- Draw buttons: d-pad + DrawRectangle(317, 202, 19, 71, BLACK) + DrawRectangle(293, 228, 69, 19, BLACK) + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_UP)) then DrawRectangle(317, 202, 19, 26, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_DOWN)) then DrawRectangle(317, 202 + 45, 19, 26, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LEFT)) then DrawRectangle(292, 228, 25, 19, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RIGHT)) then DrawRectangle(292 + 44, 228, 26, 19, RED) end + + -- Draw buttons: left-right back + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LB)) then DrawCircle(259, 61, 20, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RB)) then DrawCircle(536, 61, 20, RED) end + + -- Draw axis: left joystick + DrawCircle(259, 152, 39, BLACK) + DrawCircle(259, 152, 34, LIGHTGRAY) + DrawCircle(259 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X)*20), + 152 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y)*20), 25, BLACK) + + -- Draw axis: right joystick + DrawCircle(461, 237, 38, BLACK) + DrawCircle(461, 237, 33, LIGHTGRAY) + DrawCircle(461 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_X)*20), + 237 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_Y)*20), 25, BLACK) - DrawCircleV(ballPosition, 50, MAROON) + -- Draw axis: left-right triggers + DrawRectangle(170, 30, 15, 70, GRAY) + DrawRectangle(604, 30, 15, 70, GRAY) + DrawRectangle(170, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT))/2.0)*70), RED) + DrawRectangle(604, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT))/2.0)*70), RED) + + --DrawText(FormatText("Xbox axis LT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT)), 10, 40, 10, BLACK) + --DrawText(FormatText("Xbox axis RT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT)), 10, 60, 10, BLACK) + elseif (IsGamepadName(GAMEPAD.PLAYER1, "PLAYSTATION(R)3 Controller")) then + DrawTexture(texPs3Pad, 0, 0, DARKGRAY) + + -- Draw buttons: ps + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_PS)) then DrawCircle(396, 222, 13, RED) end + + -- Draw buttons: basic + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SELECT)) then DrawRectangle(328, 170, 32, 13, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_START)) then DrawTriangle((Vector2){ 436, 168 }, (Vector2){ 436, 185 }, (Vector2){ 464, 177 }, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_TRIANGLE)) then DrawCircle(557, 144, 13, LIME) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CIRCLE)) then DrawCircle(586, 173, 13, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CROSS)) then DrawCircle(557, 203, 13, VIOLET) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SQUARE)) then DrawCircle(527, 173, 13, PINK) end + + -- Draw buttons: d-pad + DrawRectangle(225, 132, 24, 84, BLACK) + DrawRectangle(195, 161, 84, 25, BLACK) + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_UP)) then DrawRectangle(225, 132, 24, 29, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_DOWN)) then DrawRectangle(225, 132 + 54, 24, 30, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_LEFT)) then DrawRectangle(195, 161, 30, 25, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_RIGHT)) then DrawRectangle(195 + 54, 161, 30, 25, RED) end + + -- Draw buttons: left-right back buttons + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_L1)) then DrawCircle(239, 82, 20, RED) end + if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_R1)) then DrawCircle(557, 82, 20, RED) end + + -- Draw axis: left joystick + DrawCircle(319, 255, 35, BLACK) + DrawCircle(319, 255, 31, LIGHTGRAY) + DrawCircle(319 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_X)*20), + 255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_Y)*20), 25, BLACK) + + -- Draw axis: right joystick + DrawCircle(475, 255, 35, BLACK) + DrawCircle(475, 255, 31, LIGHTGRAY) + DrawCircle(475 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_X)*20), + 255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_Y)*20), 25, BLACK) + + -- Draw axis: left-right triggers + DrawRectangle(169, 48, 15, 70, GRAY) + DrawRectangle(611, 48, 15, 70, GRAY) + DrawRectangle(169, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_L2))/2.0)*70), RED) + DrawRectangle(611, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_R2))/2.0)*70), RED) + else + DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY) + + -- TODO: Draw generic gamepad + end + + DrawText(string.format("DETECTED AXIS [%i]:", GetGamepadAxisCount(GAMEPAD.PLAYER1)), 10, 50, 10, MAROON) + + for i = 1, GetGamepadAxisCount(GAMEPAD.PLAYER1) do -- Iterate along all the rectangles + DrawText(string.format("AXIS %i: %.02f", i, GetGamepadAxisMovement(GAMEPAD.PLAYER1, i)), 20, 70 + 20*i, 10, DARKGRAY) + end + + if (GetGamepadButtonPressed() ~= -1) then DrawText(string.format("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED) + else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY) end + else + DrawText("GP1: NOT DETECTED", 10, 10, 10, GRAY) + + DrawTexture(texXboxPad, 0, 0, LIGHTGRAY) + end EndDrawing() --------------------------------------------------------------------------------------- @@ -59,5 +156,8 @@ end -- De-Initialization ------------------------------------------------------------------------------------------- -CloseWindow() -- Close window and OpenGL context +UnloadTexture(texPs3Pad) -- Unload gamepad texture +UnloadTexture(texXboxPad) -- Unload gamepad texture + +CloseWindow() -- Close window and OpenGL context ------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/examples/core_world_screen.lua b/examples/core_world_screen.lua index 51f2cdbf..48b617dd 100644 --- a/examples/core_world_screen.lua +++ b/examples/core_world_screen.lua @@ -23,10 +23,7 @@ local cubePosition = Vector3(0.0, 0.0, 0.0) local cubeScreenPosition = Vector2(0, 0) -SetCameraMode(CameraMode.FREE) -- Set a free camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ---------------------------------------------------------------------------------------- @@ -35,7 +32,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per- while not WindowShouldClose() do -- Detect window close button or ESC key -- Update ------------------------------------------------------------------------------------ - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera -- Calculate cube screen space position (with a little offset to be in top) cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera) diff --git a/examples/models_billboard.lua b/examples/models_billboard.lua index 457198e6..9d81f6ce 100644 --- a/examples/models_billboard.lua +++ b/examples/models_billboard.lua @@ -22,19 +22,16 @@ local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0. local bill = LoadTexture("resources/billboard.png") -- Our texture billboard local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/models_cubicmap.lua b/examples/models_cubicmap.lua index bae3bac2..79faafc9 100644 --- a/examples/models_cubicmap.lua +++ b/examples/models_cubicmap.lua @@ -31,18 +31,16 @@ local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position -SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/models_heightmap.lua b/examples/models_heightmap.lua index 4240f8b7..efcbfb4b 100644 --- a/examples/models_heightmap.lua +++ b/examples/models_heightmap.lua @@ -27,17 +27,16 @@ local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (d UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ---------------------------------------------------------------------------------------- -- Main game loop while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/rlua_execute_file.c b/examples/rlua_execute_file.c index f2d7114e..a91ce42f 100644 --- a/examples/rlua_execute_file.c +++ b/examples/rlua_execute_file.c @@ -66,6 +66,8 @@ int main() // ExecuteLuaFile("text_format_text.lua"); // OK! NOTE: Use lua string.format() instead of raylib FormatText() // ExecuteLuaFile("text_font_select.lua"); // OK! // ExecuteLuaFile("text_writing_anim.lua"); // OK! + // ExecuteLuaFile("text_ttf_loading.lua"); // ISSUE: Attempt to index a SpriteFont value (local 'font') + // ExecuteLuaFile("text_bmfont_unordered.lua"); // OK! // ExecuteLuaFile("models_geometric_shapes.lua"); // OK! // ExecuteLuaFile("models_box_collisions.lua"); // OK! // ExecuteLuaFile("models_billboard.lua"); // OK! @@ -81,7 +83,7 @@ int main() // ExecuteLuaFile("audio_music_stream.lua"); // OK! // ExecuteLuaFile("audio_module_playing.lua"); // OK! // ExecuteLuaFile("audio_raw_stream.lua"); // ERROR: UpdateAudioStream() - + // De-Initialization //-------------------------------------------------------------------------------------- CloseLuaDevice(); // Close Lua device and free resources diff --git a/examples/shaders_custom_uniform.lua b/examples/shaders_custom_uniform.lua index 3a8bbae5..dafd3b84 100644 --- a/examples/shaders_custom_uniform.lua +++ b/examples/shaders_custom_uniform.lua @@ -47,15 +47,13 @@ local swirlCenter = { screenWidth/2, screenHeight/2 } local target = LoadRenderTexture(screenWidth, screenHeight) -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- local mousePosition = GetMousePosition() @@ -66,7 +64,7 @@ while not WindowShouldClose() do -- Detect window close button or ESC key -- Send new value to the shader to be used on drawing SetShaderValue(shader, swirlCenterLoc, swirlCenter) - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw @@ -75,13 +73,13 @@ while not WindowShouldClose() do -- Detect window close button or ESC key ClearBackground(RAYWHITE) - BeginTextureMode(target) -- Enable drawing to texture + BeginTextureMode(target) -- Enable drawing to texture Begin3dMode(camera) DrawModel(dwarf, position, 2.0, WHITE) -- Draw 3d model with texture - DrawGrid(10, 1.0) -- Draw a grid + DrawGrid(10, 1.0) -- Draw a grid End3dMode() diff --git a/examples/shaders_model_shader.c b/examples/shaders_model_shader.c index 26de4922..51e9c1b3 100644 --- a/examples/shaders_model_shader.c +++ b/examples/shaders_model_shader.c @@ -42,7 +42,7 @@ int main() Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode + SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -52,7 +52,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/shaders_model_shader.lua b/examples/shaders_model_shader.lua index d1436a7e..38f0fd30 100644 --- a/examples/shaders_model_shader.lua +++ b/examples/shaders_model_shader.lua @@ -39,9 +39,7 @@ dwarf.material.texDiffuse = texture -- Bind texture to model local position = Vector3(0.0, 0.0, 0.0) -- Set model position -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- @@ -50,7 +48,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-pe while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/shaders_postprocessing.lua b/examples/shaders_postprocessing.lua index f20f31ec..7dfac816 100644 --- a/examples/shaders_postprocessing.lua +++ b/examples/shaders_postprocessing.lua @@ -41,18 +41,16 @@ local shader = LoadShader("resources/shaders/glsl330/base.vs", local target = LoadRenderTexture(screenWidth, screenHeight) -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/shaders_standard_lighting.lua b/examples/shaders_standard_lighting.lua index 2f3700ff..1d4dcfcf 100644 --- a/examples/shaders_standard_lighting.lua +++ b/examples/shaders_standard_lighting.lua @@ -60,18 +60,16 @@ pointLight.diffuse = Color(100, 100, 255, 255) pointLight.radius = 3.0 -- Setup orbital camera -SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode -SetCameraPosition(camera.position) -- Set internal camera position to match our camera position -SetCameraTarget(camera.target) -- Set internal camera target to match our camera target +SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode -SetTargetFPS(60) -- Set our game to run at 60 frames-per-second +SetTargetFPS(60) -- Set our game to run at 60 frames-per-second ------------------------------------------------------------------------------------------- -- Main game loop -while not WindowShouldClose() do -- Detect window close button or ESC key +while not WindowShouldClose() do -- Detect window close button or ESC key -- Update --------------------------------------------------------------------------------------- - camera = UpdateCamera(camera) -- Update internal camera and our camera + camera = UpdateCamera(camera) -- Update camera --------------------------------------------------------------------------------------- -- Draw diff --git a/examples/text_bmfont_unordered.lua b/examples/text_bmfont_unordered.lua new file mode 100644 index 00000000..f324ca19 --- /dev/null +++ b/examples/text_bmfont_unordered.lua @@ -0,0 +1,57 @@ +------------------------------------------------------------------------------------------- +-- +-- raylib [text] example - BMFont unordered chars loading and drawing +-- +-- This example has been created using raylib 1.6 (www.raylib.com) +-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +-- +-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) +-- +------------------------------------------------------------------------------------------- + +-- Initialization +------------------------------------------------------------------------------------------- +local screenWidth = 800 +local 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 +local msg = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ" + +-- NOTE: Loaded font has an unordered list of characters (chars in the range 32..255) +local font = LoadSpriteFont("resources/fonts/pixantiqua.fnt") -- BMFont (AngelCode) + +SetTargetFPS(60) +------------------------------------------------------------------------------------------- + +-- Main game loop +while not WindowShouldClose() do -- 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(string.format("Font base size: %i", font.size), 40, 80, 20, GRAY) + DrawText(string.format("Font chars number: %i", font.numChars), 40, 110, 20, GRAY) + + DrawTextEx(font, msg, Vector2(40, 180), font.size, 0, MAROON) + + EndDrawing() + --------------------------------------------------------------------------------------- +end + +-- De-Initialization +------------------------------------------------------------------------------------------- +UnloadSpriteFont(font) -- AngelCode SpriteFont unloading + +CloseWindow() -- Close window and OpenGL context +------------------------------------------------------------------------------------------- \ No newline at end of file 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(); //---------------------------------------------------------------------------------- diff --git a/examples/text_ttf_loading.lua b/examples/text_ttf_loading.lua new file mode 100644 index 00000000..26443212 --- /dev/null +++ b/examples/text_ttf_loading.lua @@ -0,0 +1,118 @@ +------------------------------------------------------------------------------------------- +-- +-- raylib [text] example - TTF loading and usage +-- +-- This example has been created using raylib 1.6 (www.raylib.com) +-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +-- +-- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5) +-- +------------------------------------------------------------------------------------------- + +-- Initialization +------------------------------------------------------------------------------------------- +local screenWidth = 800; +local screenHeight = 450; + +InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading") + +local msg = "TTF SpriteFont" + +-- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) + +-- TTF SpriteFont loading with custom generation parameters +local 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 +--font.texture = GenTextureMipmaps(font.texture) -- ISSUE: attempt to index a SpriteFont value (local 'font') + +local fontSize = font.size +local fontPosition = Vector2(40, screenHeight/2 + 50) +local textSize + +SetTextureFilter(font.texture, TextureFilter.POINT) +local currentFontFilter = 0 -- Default: FILTER_POINT + +local count = 0 +local droppedFiles + +SetTargetFPS(60) +------------------------------------------------------------------------------------------- + +-- Main game loop +while not WindowShouldClose() do -- Detect window close button or ESC key + -- Update + --------------------------------------------------------------------------------------- + fontSize = fontSize + GetMouseWheelMove()*4.0 + + -- Choose font texture filter method + if (IsKeyPressed(KEY.ONE)) then + SetTextureFilter(font.texture, TextureFilter.POINT) + currentFontFilter = 0 + elseif (IsKeyPressed(KEY.TWO)) then + SetTextureFilter(font.texture, TextureFilter.BILINEAR) + currentFontFilter = 1 + elseif (IsKeyPressed(KEY.THREE)) then + -- NOTE: Trilinear filter won't be noticed on 2D drawing + SetTextureFilter(font.texture, TextureFilter.TRILINEAR) + currentFontFilter = 2 + end + + textSize = MeasureTextEx(font, msg, fontSize, 0) + + if (IsKeyDown(KEY.LEFT)) then fontPosition.x = fontPosition.x - 10 + elseif (IsKeyDown(KEY.RIGHT)) then fontPosition.x = fontPosition.x + 10 + end + + -- Load a dropped TTF file dynamically (at current fontSize) + if (IsFileDropped()) then + droppedFiles = GetDroppedFiles() + count = #droppedFiles + + if (count == 1) then -- Only support one ttf file dropped + UnloadSpriteFont(font) + font = LoadSpriteFontTTF(droppedFiles[1], fontSize, 0, 0) + ClearDroppedFiles() + end + end + --------------------------------------------------------------------------------------- + + -- 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(string.format("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY) + DrawText(string.format("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) then DrawText("POINT", 570, 400, 20, BLACK) + elseif (currentFontFilter == 1) then DrawText("BILINEAR", 570, 400, 20, BLACK) + elseif (currentFontFilter == 2) then DrawText("TRILINEAR", 570, 400, 20, BLACK) + end + + EndDrawing() + --------------------------------------------------------------------------------------- +end + +-- De-Initialization +------------------------------------------------------------------------------------------- +UnloadSpriteFont(font) -- SpriteFont unloading + +ClearDroppedFiles() -- Clear internal buffers + +CloseWindow() -- Close window and OpenGL context +------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/rlua.h b/src/rlua.h index c801a328..961ed1c1 100644 --- a/src/rlua.h +++ b/src/rlua.h @@ -2105,8 +2105,9 @@ int lua_ImageColorBrightness(lua_State* L) int lua_GenTextureMipmaps(lua_State* L) { Texture2D arg1 = LuaGetArgument_Texture2D(L, 1); - GenTextureMipmaps(arg1); - return 0; + GenTextureMipmaps(&arg1); + LuaPush_Texture2D(L, arg1); + return 1; } int lua_SetTextureFilter(lua_State* L) @@ -4096,24 +4097,36 @@ RLUADEF void InitLuaDevice(void) LuaSetEnum("RIGHT_BUTTON", 1); LuaSetEnum("MIDDLE_BUTTON", 2); LuaEndEnum("MOUSE"); - + LuaStartEnum(); LuaSetEnum("PLAYER1", 0); LuaSetEnum("PLAYER2", 1); LuaSetEnum("PLAYER3", 2); LuaSetEnum("PLAYER4", 3); - LuaSetEnum("PS3_BUTTON_A", 2); - LuaSetEnum("PS3_BUTTON_B", 1); - LuaSetEnum("PS3_BUTTON_X", 3); - LuaSetEnum("PS3_BUTTON_Y", 4); - LuaSetEnum("PS3_BUTTON_R1", 7); - LuaSetEnum("PS3_BUTTON_R2", 5); + LuaSetEnum("PS3_BUTTON_TRIANGLE", 0); + LuaSetEnum("PS3_BUTTON_CIRCLE", 1); + LuaSetEnum("PS3_BUTTON_CROSS", 2); + LuaSetEnum("PS3_BUTTON_SQUARE", 3); LuaSetEnum("PS3_BUTTON_L1", 6); - LuaSetEnum("PS3_BUTTON_L2", 8); + LuaSetEnum("PS3_BUTTON_R1", 7); + LuaSetEnum("PS3_BUTTON_L2", 4); + LuaSetEnum("PS3_BUTTON_R2", 5); + LuaSetEnum("PS3_BUTTON_START", 8); LuaSetEnum("PS3_BUTTON_SELECT", 9); - LuaSetEnum("PS3_BUTTON_START", 10); - + LuaSetEnum("PS3_BUTTON_UP", 24); + LuaSetEnum("PS3_BUTTON_RIGHT", 25); + LuaSetEnum("PS3_BUTTON_DOWN", 26); + LuaSetEnum("PS3_BUTTON_LEFT", 27); + LuaSetEnum("PS3_BUTTON_PS", 12); + LuaSetEnum("PS3_AXIS_LEFT_X", 0); + LuaSetEnum("PS3_AXIS_LEFT_Y", 1); + LuaSetEnum("PS3_AXIS_RIGHT_X", 2); + LuaSetEnum("PS3_AXIS_RIGHT_Y", 5); + LuaSetEnum("PS3_AXIS_L2", 3); // [1..-1] (pressure-level) + LuaSetEnum("PS3_AXIS_R2", 4); // [1..-1] (pressure-level) + +// Xbox360 USB Controller Buttons LuaSetEnum("XBOX_BUTTON_A", 0); LuaSetEnum("XBOX_BUTTON_B", 1); LuaSetEnum("XBOX_BUTTON_X", 2); @@ -4122,25 +4135,26 @@ RLUADEF void InitLuaDevice(void) LuaSetEnum("XBOX_BUTTON_RB", 5); LuaSetEnum("XBOX_BUTTON_SELECT", 6); LuaSetEnum("XBOX_BUTTON_START", 7); - -#if defined(PLATFORM_RPI) - LuaSetEnum("XBOX_AXIS_DPAD_X", 7); - LuaSetEnum("XBOX_AXIS_DPAD_Y", 6); - LuaSetEnum("XBOX_AXIS_RIGHT_X", 3); - LuaSetEnum("XBOX_AXIS_RIGHT_Y", 4); - LuaSetEnum("XBOX_AXIS_LT", 2); - LuaSetEnum("XBOX_AXIS_RT", 5); -#else LuaSetEnum("XBOX_BUTTON_UP", 10); + LuaSetEnum("XBOX_BUTTON_RIGHT", 11); LuaSetEnum("XBOX_BUTTON_DOWN", 12); LuaSetEnum("XBOX_BUTTON_LEFT", 13); - LuaSetEnum("XBOX_BUTTON_RIGHT", 11); - LuaSetEnum("XBOX_AXIS_RIGHT_X", 4); - LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3); - LuaSetEnum("XBOX_AXIS_LT_RT", 2); + LuaSetEnum("XBOX_BUTTON_HOME", 8); +#if defined(PLATFORM_RPI) + LuaSetEnum("XBOX_AXIS_LEFT_X", 0); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); // [-1..1] (up->down) + LuaSetEnum("XBOX_AXIS_RIGHT_X", 3); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_RIGHT_Y", 4); // [-1..1] (up->down) + LuaSetEnum("XBOX_AXIS_LT", 2); // [-1..1] (pressure-level) + LuaSetEnum("XBOX_AXIS_RT", 5); // [-1..1] (pressure-level) +#else + LuaSetEnum("XBOX_AXIS_LEFT_X", 0); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); // [1..-1] (up->down) + LuaSetEnum("XBOX_AXIS_RIGHT_X", 2); // [-1..1] (left->right) + LuaSetEnum("XBOX_AXIS_RIGHT_Y", 3); // [1..-1] (up->down) + LuaSetEnum("XBOX_AXIS_LT", 4); // [-1..1] (pressure-level) + LuaSetEnum("XBOX_AXIS_RT", 5); // [-1..1] (pressure-level) #endif - LuaSetEnum("XBOX_AXIS_LEFT_X", 0); - LuaSetEnum("XBOX_AXIS_LEFT_Y", 1); LuaEndEnum("GAMEPAD"); lua_pushglobaltable(L); @@ -4204,6 +4218,15 @@ RLUADEF void InitLuaDevice(void) LuaSetEnum("DIRECTIONAL", LIGHT_DIRECTIONAL); LuaSetEnum("SPOT", LIGHT_SPOT); LuaEndEnum("LightType"); + + LuaStartEnum(); + LuaSetEnum("POINT", FILTER_POINT); + LuaSetEnum("BILINEAR", FILTER_BILINEAR); + LuaSetEnum("TRILINEAR", FILTER_TRILINEAR); + LuaSetEnum("ANISOTROPIC_4X", FILTER_ANISOTROPIC_4X); + LuaSetEnum("ANISOTROPIC_8X", FILTER_ANISOTROPIC_8X); + LuaSetEnum("ANISOTROPIC_16X", FILTER_ANISOTROPIC_16X); + LuaEndEnum("TextureFilter"); LuaStartEnum(); LuaSetEnum("NONE", GESTURE_NONE); -- cgit v1.2.3