aboutsummaryrefslogtreecommitdiff
path: root/examples/text_rbmf_fonts.lua
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-08-06 11:32:35 +0200
committerraysan5 <raysan5@gmail.com>2016-08-06 11:32:35 +0200
commit00c7e54d3c593dbddb036f2185e614e7e4b22a1f (patch)
tree3ef6a46031712ff9551c2711adcc9fa3045a618b /examples/text_rbmf_fonts.lua
parent5f1b4e94745303ab9df87421cdd9ffb9448fee01 (diff)
downloadraylib-00c7e54d3c593dbddb036f2185e614e7e4b22a1f.tar.gz
raylib-00c7e54d3c593dbddb036f2185e614e7e4b22a1f.zip
Add raylib lua examples
Diffstat (limited to 'examples/text_rbmf_fonts.lua')
-rw-r--r--examples/text_rbmf_fonts.lua87
1 files changed, 87 insertions, 0 deletions
diff --git a/examples/text_rbmf_fonts.lua b/examples/text_rbmf_fonts.lua
new file mode 100644
index 00000000..d89e4071
--- /dev/null
+++ b/examples/text_rbmf_fonts.lua
@@ -0,0 +1,87 @@
+-------------------------------------------------------------------------------------------
+--
+-- raylib [text] example - raylib bitmap font (rbmf) loading and usage
+--
+-- NOTE: raylib is distributed with some free to use fonts (even for commercial pourposes!)
+-- To view details and credits for those fonts, check raylib license file
+--
+-- 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 - rBMF fonts")
+
+-- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
+local fonts = {}
+
+fonts[1] = LoadSpriteFont("resources/fonts/alagard.rbmf") -- rBMF font loading
+fonts[2] = LoadSpriteFont("resources/fonts/pixelplay.rbmf") -- rBMF font loading
+fonts[3] = LoadSpriteFont("resources/fonts/mecha.rbmf") -- rBMF font loading
+fonts[4] = LoadSpriteFont("resources/fonts/setback.rbmf") -- rBMF font loading
+fonts[5] = LoadSpriteFont("resources/fonts/romulus.rbmf") -- rBMF font loading
+fonts[6] = LoadSpriteFont("resources/fonts/pixantiqua.rbmf") -- rBMF font loading
+fonts[7] = LoadSpriteFont("resources/fonts/alpha_beta.rbmf") -- rBMF font loading
+fonts[8] = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf") -- rBMF font loading
+
+local messages = { "ALAGARD FONT designed by Hewett Tsoi",
+ "PIXELPLAY FONT designed by Aleksander Shevchuk",
+ "MECHA FONT designed by Captain Falcon",
+ "SETBACK FONT designed by Brian Kent (AEnigma)",
+ "ROMULUS FONT designed by Hewett Tsoi",
+ "PIXANTIQUA FONT designed by Gerhard Grossmann",
+ "ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
+ "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" }
+
+local spacings = { 2, 4, 8, 4, 3, 4, 4, 1 }
+
+local positions = {}
+
+for i = 1, 8 do
+ positions[i] = Vector2(0, 0)
+ positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].size*2, spacings[i]).x/2
+ positions[i].y = 60 + fonts[i].size + 50*i
+end
+
+local colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD }
+
+SetTargetFPS(60) -- Set target frames-per-second
+-------------------------------------------------------------------------------------------
+
+-- Main game loop
+while not WindowShouldClose() do -- Detect window close button or ESC key
+ -- Update
+ ---------------------------------------------------------------------------------------
+ -- TODO: Update your variables here
+ ---------------------------------------------------------------------------------------
+
+ -- Draw
+ ---------------------------------------------------------------------------------------
+ BeginDrawing()
+
+ ClearBackground(RAYWHITE)
+
+ DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY)
+ DrawLine(220, 50, 590, 50, DARKGRAY)
+
+ for i = 1, 8 do
+ DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].size*2, spacings[i], colors[i])
+ end
+
+ EndDrawing()
+ ---------------------------------------------------------------------------------------
+end
+
+-- De-Initialization
+-------------------------------------------------------------------------------------------
+for i = 1, 8 do UnloadSpriteFont(fonts[i]) end -- SpriteFont unloading
+
+CloseWindow() -- Close window and OpenGL context
+------------------------------------------------------------------------------------------- \ No newline at end of file