From d0b248d09ddceee0bdf86ca8bdb45fd30077070c Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Sat, 25 Jan 2025 02:08:05 +0000 Subject: [PATCH] Enable fullscreen --- src/main.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index ddb6816..934e039 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,9 @@ #include "resource_dir.h" // utility header for SearchAndSetResourceDir #include +const short int WINDOW_WIDTH = 1280; +const short int WINDOW_HEIGHT = 800; + int main () { struct MenuItem item[] = { @@ -13,12 +16,21 @@ int main () size_t current_item = 0; size_t items_len = sizeof(item) / sizeof(struct MenuItem); - // Tell the window to use vsync and work on high DPI displays - SetConfigFlags(FLAG_VSYNC_HINT | FLAG_WINDOW_HIGHDPI); + // SetConfigFlags(FLAG_VSYNC_HINT | FLAG_WINDOW_HIGHDPI); + SetConfigFlags(FLAG_VSYNC_HINT); // Create the window and OpenGL context - InitWindow(1280, 800, "Touhou Jikuusen ~ Apotheotic Heterochronicity"); + InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Touhou Jikuusen ~ Apotheotic Heterochronicity"); + + HideCursor(); + // see what display we are on right now + int display = GetCurrentMonitor(); + + const int MONITOR_WIDTH = GetMonitorWidth(display); + const int MONITOR_HEIGHT = GetMonitorHeight(display); + + printf("Size of monitor: %dx%d\n", MONITOR_WIDTH, MONITOR_HEIGHT); // Set the framerate to 60fps SetTargetFPS(60); @@ -27,15 +39,18 @@ int main () // Load a texture from the resources directory Texture wabbit = LoadTexture("wabbit_alpha.png"); - + + RenderTexture2D canvas = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT); + // game loop while (!WindowShouldClose()) // run the loop untill the user presses ESCAPE or presses the Close button on the window { - // drawing - BeginDrawing(); + // drawing onto the game screen buffer, which may be centered and surrounded in black bars + // in fullscreen mode + BeginTextureMode(canvas); // Setup the back buffer for drawing (clear color and depth buffers) - ClearBackground(BLACK); + ClearBackground(GREEN); for (int i = 0; i < items_len; i++) { @@ -52,12 +67,27 @@ int main () current_item--; } } + + if (IsKeyPressed(KEY_ENTER) && (IsKeyDown(KEY_LEFT_ALT) || IsKeyDown(KEY_RIGHT_ALT))) { + // toggle the state + ToggleFullscreen(); + } + // draw some text using the default font DrawText("TOUHOU!!!!", 200,200,20,WHITE); // draw our texture to the screen DrawTexture(wabbit, 400, 200, WHITE); + + // finish rendering to canvas + EndTextureMode(); + + BeginDrawing(); + // place the contents of the canvas onto the screen + ClearBackground(WHITE); + DrawTextureRec(canvas.texture, (Rectangle){.x = 0, .y = 0, .width = WINDOW_WIDTH, .height = -WINDOW_HEIGHT}, (Vector2){.x = 0, .y=0}, WHITE); + DrawCircle(GetMouseX(), GetMouseY(), 10, WHITE); // end the frame and get ready for the next one (display frame, poll input, etc...) EndDrawing(); }