1/*******************************************************************************************
2*
3* raylib [text] example - raylib font loading and usage
4*
5* NOTE: raylib is distributed with some free to use fonts (even for commercial pourposes!)
6* To view details and credits for those fonts, check raylib license file
7*
8* This example has been created using raylib 1.7 (www.raylib.com)
9* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
10*
11* Copyright (c) 2017 Ramon Santamaria (@raysan5)
12*
13********************************************************************************************/
14
15#include "raylib.h"
16
17#define MAX_FONTS 8
18
19int main(void)
20{
21 // Initialization
22 //--------------------------------------------------------------------------------------
23 const int screenWidth = 800;
24 const int screenHeight = 450;
25
26 InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts");
27
28 // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
29 Font fonts[MAX_FONTS] = { 0 };
30
31 fonts[0] = LoadFont("resources/fonts/alagard.png");
32 fonts[1] = LoadFont("resources/fonts/pixelplay.png");
33 fonts[2] = LoadFont("resources/fonts/mecha.png");
34 fonts[3] = LoadFont("resources/fonts/setback.png");
35 fonts[4] = LoadFont("resources/fonts/romulus.png");
36 fonts[5] = LoadFont("resources/fonts/pixantiqua.png");
37 fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
38 fonts[7] = LoadFont("resources/fonts/jupiter_crash.png");
39
40 const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi",
41 "PIXELPLAY FONT designed by Aleksander Shevchuk",
42 "MECHA FONT designed by Captain Falcon",
43 "SETBACK FONT designed by Brian Kent (AEnigma)",
44 "ROMULUS FONT designed by Hewett Tsoi",
45 "PIXANTIQUA FONT designed by Gerhard Grossmann",
46 "ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
47 "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
48
49 const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 };
50
51 Vector2 positions[MAX_FONTS] = { 0 };
52
53 for (int i = 0; i < MAX_FONTS; i++)
54 {
55 positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x/2;
56 positions[i].y = 60 + fonts[i].baseSize + 45*i;
57 }
58
59 // Small Y position corrections
60 positions[3].y += 8;
61 positions[4].y += 2;
62 positions[7].y -= 8;
63
64 Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
65
66 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
67 //--------------------------------------------------------------------------------------
68
69 // Main game loop
70 while (!WindowShouldClose()) // Detect window close button or ESC key
71 {
72 // Update
73 //----------------------------------------------------------------------------------
74 // TODO: Update your variables here
75 //----------------------------------------------------------------------------------
76
77 // Draw
78 //----------------------------------------------------------------------------------
79 BeginDrawing();
80
81 ClearBackground(RAYWHITE);
82
83 DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
84 DrawLine(220, 50, 590, 50, DARKGRAY);
85
86 for (int i = 0; i < MAX_FONTS; i++)
87 {
88 DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
89 }
90
91 EndDrawing();
92 //----------------------------------------------------------------------------------
93 }
94
95 // De-Initialization
96 //--------------------------------------------------------------------------------------
97
98 // Fonts unloading
99 for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);
100
101 CloseWindow(); // Close window and OpenGL context
102 //--------------------------------------------------------------------------------------
103
104 return 0;
105}