diff --git a/examples/README.md b/examples/README.md index 0d7e870..3b724ba 100644 --- a/examples/README.md +++ b/examples/README.md @@ -60,6 +60,7 @@ Examples using raylib text functionality, including sprite fonts loading/generat | ## | example | image | difficulty
level | version
created | last version
updated | original
developer | |----|------------------------------------------------------|--------|:-------------------:|:------------------:|:------------------:|:----------| +| 69 | [text_raylib_fonts](text/text_raylib_fonts.rb) | text_raylib_fonts | ⭐️☆☆☆ | 1.7 | 3.7 | [Ray](https://github.com/raysan5) | | 70 | [text_font_spritefont](text/text_font_spritefont.rb) | text_font_spritefont | ⭐️☆☆☆ | 1.0 | 1.0 | [Ray](https://github.com/raysan5) | | 71 | [text_font_filters](text/text_font_filters.rb) | text_font_filters | ⭐️⭐️☆☆ | 1.3 | **4.2** | [Ray](https://github.com/raysan5) | | 72 | [text_font_loading](text/text_font_loading.rb) | text_font_loading | ⭐️☆☆☆ | 1.4 | 3.0 | [Ray](https://github.com/raysan5) | diff --git a/examples/text/resources/LICENSE.md b/examples/text/resources/LICENSE.md index f6bf29b..52c9d28 100644 --- a/examples/text/resources/LICENSE.md +++ b/examples/text/resources/LICENSE.md @@ -1,5 +1,12 @@ | resource | author | licence | notes | | :----------------------------- | :---------: | :------ | :---- | +| fonts/alagard.png | Hewett Tsoi | [Freeware](https://www.dafont.com/es/alagard.font) | Atlas created by [@raysan5](https://github.com/raysan5) | +| fonts/romulus.png | Hewett Tsoi | [Freeware](https://www.dafont.com/es/romulus.font) | Atlas created by [@raysan5](https://github.com/raysan5) | +| fonts/alpha_beta.png | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/alpha-beta.font) | Atlas created by [@raysan5](https://github.com/raysan5) | +| fonts/setback.png | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/setback.font) | Atlas created by [@raysan5](https://github.com/raysan5) | +| fonts/jupiter_crash.png | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | +| fonts/mecha.png | Captain Falcon | [Freeware](https://www.dafont.com/es/mecha-cf.font) | Atlas created by [@raysan5](https://github.com/raysan5) | +| fonts/pixelplay.png | Aleksander Shevchuk | [Freeware](https://www.dafont.com/es/pixelplay.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/pixantiqua.ttf | Gerhard Großmann | [Freeware](https://www.dafont.com/es/pixantiqua.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | custom_alagard.png | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | custom_jupiter_crash.png | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | diff --git a/examples/text/resources/fonts/alagard.png b/examples/text/resources/fonts/alagard.png new file mode 100644 index 0000000..e8d15ee Binary files /dev/null and b/examples/text/resources/fonts/alagard.png differ diff --git a/examples/text/resources/fonts/alpha_beta.png b/examples/text/resources/fonts/alpha_beta.png new file mode 100644 index 0000000..6b880bd Binary files /dev/null and b/examples/text/resources/fonts/alpha_beta.png differ diff --git a/examples/text/resources/fonts/jupiter_crash.png b/examples/text/resources/fonts/jupiter_crash.png new file mode 100644 index 0000000..064df10 Binary files /dev/null and b/examples/text/resources/fonts/jupiter_crash.png differ diff --git a/examples/text/resources/fonts/mecha.png b/examples/text/resources/fonts/mecha.png new file mode 100644 index 0000000..88c2df7 Binary files /dev/null and b/examples/text/resources/fonts/mecha.png differ diff --git a/examples/text/resources/fonts/pixelplay.png b/examples/text/resources/fonts/pixelplay.png new file mode 100644 index 0000000..5d5d563 Binary files /dev/null and b/examples/text/resources/fonts/pixelplay.png differ diff --git a/examples/text/resources/fonts/romulus.png b/examples/text/resources/fonts/romulus.png new file mode 100644 index 0000000..37b8f63 Binary files /dev/null and b/examples/text/resources/fonts/romulus.png differ diff --git a/examples/text/resources/fonts/setback.png b/examples/text/resources/fonts/setback.png new file mode 100644 index 0000000..7331c95 Binary files /dev/null and b/examples/text/resources/fonts/setback.png differ diff --git a/examples/text/text_raylib_fonts.png b/examples/text/text_raylib_fonts.png new file mode 100644 index 0000000..8f428a6 Binary files /dev/null and b/examples/text/text_raylib_fonts.png differ diff --git a/examples/text/text_raylib_fonts.rb b/examples/text/text_raylib_fonts.rb new file mode 100644 index 0000000..1b58b71 --- /dev/null +++ b/examples/text/text_raylib_fonts.rb @@ -0,0 +1,103 @@ +# ****************************************************************************************** +# +# raylib [text] example - raylib fonts loading +# +# NOTE: raylib is distributed with some free to use fonts (even for commercial purposes!) +# To view details and credits for those fonts, check raylib license file +# +# Example originally created with raylib 1.7, last time updated with raylib 3.7 +# +# Example ported to Ruby by Wilson Silva (@wilsonsilva). Works with Raylib 4.5 +# +# Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +# BSD-like license that allows static linking with closed source software +# +# Copyright (c) 2017-2023 Ramon Santamaria (@raysan5) +# +# ****************************************************************************************** + +require 'bundler/setup' +require 'raylib' + +MAX_FONTS = 8 + +# Initialization +# -------------------------------------------------------------------------------------- +SCREEN_WIDTH = 800 +SCREEN_HEIGHT = 450 + +Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [text] example - raylib fonts") + +# NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) +fonts = Array.new(MAX_FONTS) +fonts[0] = Raylib.load_font(File.join(__dir__, "resources/fonts/alagard.png")) +fonts[1] = Raylib.load_font(File.join(__dir__, "resources/fonts/pixelplay.png")) +fonts[2] = Raylib.load_font(File.join(__dir__, "resources/fonts/mecha.png")) +fonts[3] = Raylib.load_font(File.join(__dir__, "resources/fonts/setback.png")) +fonts[4] = Raylib.load_font(File.join(__dir__, "resources/fonts/romulus.png")) +fonts[5] = Raylib.load_font(File.join(__dir__, "resources/fonts/pixantiqua.png")) +fonts[6] = Raylib.load_font(File.join(__dir__, "resources/fonts/alpha_beta.png")) +fonts[7] = Raylib.load_font(File.join(__dir__, "resources/fonts/jupiter_crash.png")) + +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)" +] + +spacings = [2, 4, 8, 4, 3, 4, 4, 1] +positions = Array.new(MAX_FONTS) { Raylib::Vector2.create(0.0, 0.0) } + +MAX_FONTS.times do |i| + positions[i].x = SCREEN_WIDTH / 2.0 - Raylib.measure_text_ex(fonts[i], messages[i], fonts[i].base_size * 2.0, spacings[i].to_f).x / 2.0 + positions[i].y = 60.0 + fonts[i].base_size + 45.0 * i +end + +# Small Y position corrections +positions[3].y += 8 +positions[4].y += 2 +positions[7].y -= 8 + +colors = [ + Raylib::MAROON, + Raylib::ORANGE, + Raylib::DARKGREEN, + Raylib::DARKBLUE, + Raylib::DARKPURPLE, + Raylib::LIME, + Raylib::GOLD, + Raylib::RED +] + +Raylib.set_target_fps(60) +# -------------------------------------------------------------------------------------- + +# Main game loop +until Raylib.window_should_close + # Draw + # ---------------------------------------------------------------------------------- + Raylib.begin_drawing + Raylib.clear_background(Raylib::RAYWHITE) + + Raylib.draw_text("free fonts included with raylib", 250, 20, 20, Raylib::DARKGRAY) + Raylib.draw_line(220, 50, 590, 50, Raylib::DARKGRAY) + + MAX_FONTS.times do |i| + Raylib.draw_text_ex(fonts[i], messages[i], positions[i], fonts[i].base_size * 2.0, spacings[i].to_f, colors[i]) + end + + Raylib.end_drawing + # ---------------------------------------------------------------------------------- +end + +# De-Initialization +# -------------------------------------------------------------------------------------- +fonts.each { |font| Raylib.unload_font(font) } # Fonts unloading + +Raylib.close_window # Close window and OpenGL context +# --------------------------------------------------------------------------------------