2013-11-24 20:30:05 +01:00
|
|
|
/*******************************************************************************************
|
|
|
|
|
*
|
2025-08-25 20:57:18 +02:00
|
|
|
* raylib [text] example - sprite fonts
|
2014-09-21 14:26:42 +02:00
|
|
|
*
|
2025-01-17 03:42:30 -06:00
|
|
|
* Example complexity rating: [★☆☆☆] 1/4
|
|
|
|
|
*
|
2014-09-21 14:26:42 +02:00
|
|
|
* 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
|
2013-11-24 20:30:05 +01:00
|
|
|
*
|
2022-07-20 01:28:37 +02:00
|
|
|
* Example originally created with raylib 1.7, last time updated with raylib 3.7
|
2013-11-24 20:30:05 +01:00
|
|
|
*
|
2022-07-20 01:28:37 +02:00
|
|
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
|
|
|
* BSD-like license that allows static linking with closed source software
|
|
|
|
|
*
|
2025-01-18 10:41:56 -08:00
|
|
|
* Copyright (c) 2017-2025 Ramon Santamaria (@raysan5)
|
2013-11-24 20:30:05 +01:00
|
|
|
*
|
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
2013-12-27 00:17:39 +01:00
|
|
|
#include "raylib.h"
|
2013-11-24 20:30:05 +01:00
|
|
|
|
2017-04-16 19:08:19 +02:00
|
|
|
#define MAX_FONTS 8
|
|
|
|
|
|
2022-06-21 19:53:18 +02:00
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
|
// Program main entry point
|
|
|
|
|
//------------------------------------------------------------------------------------
|
2019-05-20 16:36:42 +02:00
|
|
|
int main(void)
|
2013-11-24 20:30:05 +01:00
|
|
|
{
|
2013-11-28 19:59:56 +01:00
|
|
|
// Initialization
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
2019-05-20 16:36:42 +02:00
|
|
|
const int screenWidth = 800;
|
|
|
|
|
const int screenHeight = 450;
|
2013-11-28 19:59:56 +01:00
|
|
|
|
2025-08-19 13:22:15 +02:00
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts");
|
2014-09-29 23:41:05 +02:00
|
|
|
|
2013-11-24 20:30:05 +01:00
|
|
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
2019-05-27 00:18:15 +02:00
|
|
|
Font fonts[MAX_FONTS] = { 0 };
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2025-08-19 13:22:15 +02:00
|
|
|
fonts[0] = LoadFont("resources/sprite_fonts/alagard.png");
|
|
|
|
|
fonts[1] = LoadFont("resources/sprite_fonts/pixelplay.png");
|
|
|
|
|
fonts[2] = LoadFont("resources/sprite_fonts/mecha.png");
|
|
|
|
|
fonts[3] = LoadFont("resources/sprite_fonts/setback.png");
|
|
|
|
|
fonts[4] = LoadFont("resources/sprite_fonts/romulus.png");
|
|
|
|
|
fonts[5] = LoadFont("resources/sprite_fonts/pixantiqua.png");
|
|
|
|
|
fonts[6] = LoadFont("resources/sprite_fonts/alpha_beta.png");
|
|
|
|
|
fonts[7] = LoadFont("resources/sprite_fonts/jupiter_crash.png");
|
2019-05-20 16:36:42 +02:00
|
|
|
|
|
|
|
|
const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi",
|
2015-08-27 16:13:31 +02:00
|
|
|
"PIXELPLAY FONT designed by Aleksander Shevchuk",
|
2019-05-20 16:36:42 +02:00
|
|
|
"MECHA FONT designed by Captain Falcon",
|
|
|
|
|
"SETBACK FONT designed by Brian Kent (AEnigma)",
|
|
|
|
|
"ROMULUS FONT designed by Hewett Tsoi",
|
2015-08-27 16:13:31 +02:00
|
|
|
"PIXANTIQUA FONT designed by Gerhard Grossmann",
|
|
|
|
|
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
|
|
|
|
|
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2017-04-16 19:08:19 +02:00
|
|
|
const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 };
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2019-05-27 00:18:15 +02:00
|
|
|
Vector2 positions[MAX_FONTS] = { 0 };
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2017-04-16 19:08:19 +02:00
|
|
|
for (int i = 0; i < MAX_FONTS; i++)
|
2015-08-27 16:13:31 +02:00
|
|
|
{
|
2021-04-25 09:50:26 -07:00
|
|
|
positions[i].x = screenWidth/2.0f - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2.0f, (float)spacings[i]).x/2.0f;
|
|
|
|
|
positions[i].y = 60.0f + fonts[i].baseSize + 45.0f*i;
|
2015-08-27 16:13:31 +02:00
|
|
|
}
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2017-04-16 19:08:19 +02:00
|
|
|
// Small Y position corrections
|
|
|
|
|
positions[3].y += 8;
|
|
|
|
|
positions[4].y += 2;
|
|
|
|
|
positions[7].y -= 8;
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2017-04-16 19:08:19 +02:00
|
|
|
Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
|
2021-04-22 18:55:24 +02:00
|
|
|
|
2019-05-20 16:36:42 +02:00
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
2013-11-28 19:59:56 +01:00
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-29 23:41:05 +02:00
|
|
|
|
2013-11-24 20:30:05 +01:00
|
|
|
// Main game loop
|
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
|
{
|
|
|
|
|
// Update
|
2013-11-28 19:59:56 +01:00
|
|
|
//----------------------------------------------------------------------------------
|
2013-11-24 20:30:05 +01:00
|
|
|
// TODO: Update your variables here
|
2013-11-28 19:59:56 +01:00
|
|
|
//----------------------------------------------------------------------------------
|
2014-09-29 23:41:05 +02:00
|
|
|
|
2013-11-24 20:30:05 +01:00
|
|
|
// Draw
|
2013-11-28 19:59:56 +01:00
|
|
|
//----------------------------------------------------------------------------------
|
2013-11-24 20:30:05 +01:00
|
|
|
BeginDrawing();
|
2014-09-29 23:41:05 +02:00
|
|
|
|
2013-11-24 20:30:05 +01:00
|
|
|
ClearBackground(RAYWHITE);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2025-08-19 13:22:15 +02:00
|
|
|
DrawText("free sprite fonts included with raylib", 220, 20, 20, DARKGRAY);
|
|
|
|
|
DrawLine(220, 50, 600, 50, DARKGRAY);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2017-04-16 19:08:19 +02:00
|
|
|
for (int i = 0; i < MAX_FONTS; i++)
|
2015-08-27 16:13:31 +02:00
|
|
|
{
|
2021-03-22 23:51:52 -07:00
|
|
|
DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2.0f, (float)spacings[i], colors[i]);
|
2015-08-27 16:13:31 +02:00
|
|
|
}
|
2014-09-29 23:41:05 +02:00
|
|
|
|
2013-11-24 20:30:05 +01:00
|
|
|
EndDrawing();
|
2013-11-28 19:59:56 +01:00
|
|
|
//----------------------------------------------------------------------------------
|
2013-11-24 20:30:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// De-Initialization
|
2013-11-28 19:59:56 +01:00
|
|
|
//--------------------------------------------------------------------------------------
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2018-05-04 16:59:48 +02:00
|
|
|
// Fonts unloading
|
|
|
|
|
for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);
|
2014-09-29 23:41:05 +02:00
|
|
|
|
2013-12-19 12:08:06 +01:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
2013-11-28 19:59:56 +01:00
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-29 23:41:05 +02:00
|
|
|
|
2013-11-24 20:30:05 +01:00
|
|
|
return 0;
|
2014-09-21 14:26:42 +02:00
|
|
|
}
|