MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / main

Function main

examples/text/text_font_spritefont.cpp:16–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "raylib-cpp.hpp"
15
16int main(void)
17{
18 // Initialization
19 //--------------------------------------------------------------------------------------
20 const int screenWidth = 800;
21 const int screenHeight = 450;
22
23 raylib::Window window(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage");
24
25 std::string msg1 = "THIS IS A custom SPRITE FONT...";
26 std::string msg2 = "...and this is ANOTHER CUSTOM font...";
27 std::string msg3 = "...and a THIRD one! GREAT! :D";
28
29 // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
30 raylib::Font font1("resources/custom_mecha.png"); // Font loading
31 raylib::Font font2("resources/custom_alagard.png"); // Font loading
32 raylib::Font font3("resources/custom_jupiter_crash.png"); // Font loading
33
34 raylib::Vector2 fontPosition1(screenWidth/2 - MeasureTextEx(font1, msg1.c_str(), font1.baseSize, -3).x/2,
35 screenHeight/2 - font1.baseSize/2 - 80);
36
37 raylib::Vector2 fontPosition2(screenWidth/2 - MeasureTextEx(font2, msg2.c_str(), font2.baseSize, -2).x/2,
38 screenHeight/2 - font2.baseSize/2 - 10);
39
40 raylib::Vector2 fontPosition3(screenWidth/2 - MeasureTextEx(font3, msg3.c_str(), font3.baseSize, 2).x/2,
41 screenHeight/2 - font3.baseSize/2 + 50);
42
43 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
44 //--------------------------------------------------------------------------------------
45
46 // Main game loop
47 while (!window.ShouldClose()) { // Detect window close button or ESC key
48 // Update
49 //----------------------------------------------------------------------------------
50 // TODO: Update variables here...
51 //----------------------------------------------------------------------------------
52
53 // Draw
54 //----------------------------------------------------------------------------------
55 BeginDrawing();
56 {
57 window.ClearBackground(RAYWHITE);
58
59 font1.DrawText(msg1, fontPosition1, font1.baseSize, -3);
60 font2.DrawText(msg2, fontPosition2, font2.baseSize, -2);
61 font3.DrawText(msg3, fontPosition3, font3.baseSize, 2);
62 }
63 EndDrawing();
64 //----------------------------------------------------------------------------------
65 }
66
67 return 0;
68}

Callers

nothing calls this directly

Calls 3

c_strMethod · 0.80
ShouldCloseMethod · 0.80
DrawTextMethod · 0.80

Tested by

no test coverage detected