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

Function main

examples/core/core_window_letterbox.cpp:26–110  ·  view source on GitHub ↗

------------------------------------------------------------------------------------ Program main entry point ------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

24// Program main entry point
25//------------------------------------------------------------------------------------
26int main(void)
27{
28 const int windowWidth = 800;
29 const int windowHeight = 450;
30
31 // Enable config flags for resizable window and vertical synchro
32 raylib::Window window(windowWidth, windowHeight,
33 "raylib [core] example - window scale letterbox",
34 FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
35 window.SetMinSize(320, 240);
36
37 int gameScreenWidth = 640;
38 int gameScreenHeight = 480;
39
40 // Render texture initialization, used to hold the rendering result so we can easily resize it
41 raylib::RenderTexture2D target(gameScreenWidth, gameScreenHeight);
42 target.GetTexture().SetFilter(TEXTURE_FILTER_BILINEAR); // Texture scale filter to use
43
44 raylib::Color colors[10];
45 for (int i = 0; i < 10; i++) {
46 colors[i] = raylib::Color((unsigned char)GetRandomValue(100, 250), (unsigned char)GetRandomValue(50, 150), (unsigned char)GetRandomValue(10, 100), 255);
47 }
48
49 window.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
50 //--------------------------------------------------------------------------------------
51
52 // Main game loop
53 while (!window.ShouldClose()) // Detect window close button or ESC key
54 {
55 // Update
56 //----------------------------------------------------------------------------------
57 // Compute required framebuffer scaling
58 float scale = MIN((float)GetScreenWidth()/gameScreenWidth, (float)GetScreenHeight()/gameScreenHeight);
59
60 if (IsKeyPressed(KEY_SPACE))
61 {
62 // Recalculate random colors for the bars
63 for (int i = 0; i < 10; i++) {
64 colors[i] = raylib::Color((unsigned char)GetRandomValue(100, 250), (unsigned char)GetRandomValue(50, 150), (unsigned char)GetRandomValue(10, 100), 255);
65 }
66 }
67
68 // Update virtual mouse (clamped mouse value behind game screen)
69 raylib::Vector2 mouse = raylib::Mouse::GetPosition();
70 raylib::Vector2 virtualMouse(
71 (mouse.x - (GetScreenWidth() - (gameScreenWidth*scale))*0.5f)/scale,
72 (mouse.y - (GetScreenHeight() - (gameScreenHeight*scale))*0.5f)/scale
73 );
74 virtualMouse = virtualMouse.Clamp(raylib::Vector2::Zero(), raylib::Vector2(gameScreenWidth, gameScreenHeight));
75
76 // Apply the same transformation as the virtual mouse to the real mouse (i.e. to work with raygui)
77 //SetMouseOffset(-(GetScreenWidth() - (gameScreenWidth*scale))*0.5f, -(GetScreenHeight() - (gameScreenHeight*scale))*0.5f);
78 //SetMouseScale(1/scale, 1/scale);
79 //----------------------------------------------------------------------------------
80
81 // Draw
82 //----------------------------------------------------------------------------------
83 // Draw everything in the render texture, note this will not be rendered on screen, yet

Callers

nothing calls this directly

Calls 11

IsKeyPressedFunction · 0.85
Vector2Class · 0.85
RectangleClass · 0.85
ShouldCloseMethod · 0.80
ColorFunction · 0.50
GetPositionFunction · 0.50
ZeroFunction · 0.50
DrawRectangleFunction · 0.50
DrawTextFunction · 0.50
GetTextureMethod · 0.45
DrawMethod · 0.45

Tested by

no test coverage detected