|
|
@ -1,19 +1,21 @@ |
|
|
|
/******************************************************************************************* |
|
|
|
* |
|
|
|
* raylib [text] example - raylib bitmap font (rbmf) loading and usage |
|
|
|
* raylib [text] example - raylib font 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.3 (www.raylib.com) |
|
|
|
* This example has been created using raylib 1.7 (www.raylib.com) |
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
|
|
|
* |
|
|
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5) |
|
|
|
* Copyright (c) 2017 Ramon Santamaria (@raysan5) |
|
|
|
* |
|
|
|
********************************************************************************************/ |
|
|
|
|
|
|
|
#include "raylib.h" |
|
|
|
|
|
|
|
#define MAX_FONTS 8 |
|
|
|
|
|
|
|
int main() |
|
|
|
{ |
|
|
|
// Initialization |
|
|
@ -21,21 +23,21 @@ int main() |
|
|
|
int screenWidth = 800; |
|
|
|
int screenHeight = 450; |
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - rBMF fonts"); |
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts"); |
|
|
|
|
|
|
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) |
|
|
|
SpriteFont fonts[mi">8]; |
|
|
|
SpriteFont fonts[n">MAX_FONTS]; |
|
|
|
|
|
|
|
fonts[0] = LoadSpriteFont("resources/fonts/alagard.rbmf"); // rBMF font loading |
|
|
|
fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // rBMF font loading |
|
|
|
fonts[2] = LoadSpriteFont("resources/fonts/mecha.rbmf"); // rBMF font loading |
|
|
|
fonts[3] = LoadSpriteFont("resources/fonts/setback.rbmf"); // rBMF font loading |
|
|
|
fonts[4] = LoadSpriteFont("resources/fonts/romulus.rbmf"); // rBMF font loading |
|
|
|
fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.rbmf"); // rBMF font loading |
|
|
|
fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.rbmf"); // rBMF font loading |
|
|
|
fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf"); // rBMF font loading |
|
|
|
fonts[0] = LoadSpriteFont("resources/fonts/alagard.png"); |
|
|
|
fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.png"); |
|
|
|
fonts[2] = LoadSpriteFont("resources/fonts/mecha.png"); |
|
|
|
fonts[3] = LoadSpriteFont("resources/fonts/setback.png"); |
|
|
|
fonts[4] = LoadSpriteFont("resources/fonts/romulus.png"); |
|
|
|
fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.png"); |
|
|
|
fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.png"); |
|
|
|
fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.png"); |
|
|
|
|
|
|
|
const char *messages[mi">8] = { "ALAGARD FONT designed by Hewett Tsoi", |
|
|
|
const char *messages[n">MAX_FONTS] = { "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)", |
|
|
@ -44,17 +46,22 @@ int main() |
|
|
|
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)", |
|
|
|
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" }; |
|
|
|
|
|
|
|
const int spacings[mi">8] = { 2, 4, 8, 4, 3, 4, 4, 1 }; |
|
|
|
const int spacings[n">MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 }; |
|
|
|
|
|
|
|
Vector2 positions[mi">8]; |
|
|
|
Vector2 positions[n">MAX_FONTS]; |
|
|
|
|
|
|
|
for (int i = 0; i < mi">8; i++) |
|
|
|
for (int i = 0; i < n">MAX_FONTS; i++) |
|
|
|
{ |
|
|
|
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x/2; |
|
|
|
positions[i].y = 60 + fonts[i].baseSize + 50*i; |
|
|
|
positions[i].y = 60 + fonts[i].baseSize + 45*i; |
|
|
|
} |
|
|
|
|
|
|
|
Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD }; |
|
|
|
// Small Y position corrections |
|
|
|
positions[3].y += 8; |
|
|
|
positions[4].y += 2; |
|
|
|
positions[7].y -= 8; |
|
|
|
|
|
|
|
Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }; |
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
// Main game loop |
|
|
@ -74,7 +81,7 @@ int main() |
|
|
|
DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY); |
|
|
|
DrawLine(220, 50, 590, 50, DARKGRAY); |
|
|
|
|
|
|
|
for (int i = 0; i < mi">8; i++) |
|
|
|
for (int i = 0; i < n">MAX_FONTS; i++) |
|
|
|
{ |
|
|
|
DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]); |
|
|
|
} |
|
|
@ -87,7 +94,7 @@ int main() |
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
// SpriteFonts unloading |
|
|
|
for (int i = 0; i < mi">8; i++) UnloadSpriteFont(fonts[i]); |
|
|
|
for (int i = 0; i < n">MAX_FONTS; i++) UnloadSpriteFont(fonts[i]); |
|
|
|
|
|
|
|
CloseWindow(); // Close window and OpenGL context |
|
|
|
//-------------------------------------------------------------------------------------- |