Skip to content

Instantly share code, notes, and snippets.

@JeffM2501
Created March 7, 2021 17:40
Show Gist options
  • Save JeffM2501/00cf5653f41337d8c9e8db40deb25656 to your computer and use it in GitHub Desktop.
Save JeffM2501/00cf5653f41337d8c9e8db40deb25656 to your computer and use it in GitHub Desktop.
Raylib resize fullscreen example
/*******************************************************************************************
*
* raylib [core] example - fullscreen toggle
*
* Welcome to raylib!
*
* To test examples, just press F6 and execute raylib_compile_execute script
* Note that compiled executable is placed in the same folder as .c file
*
* You can find all basic examples on C:\raylib\raylib\examples folder or
* raylib official webpage: www.raylib.com
*
* Enjoy using raylib. :)
*
* This example has been created using raylib 3.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2013-2021 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
InitWindow(screenWidth, screenHeight, "raylib [core] example - fullscreen toggle");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
if (IsWindowResized() && !IsWindowFullscreen())
{
screenWidth = GetScreenWidth();
screenHeight = GetScreenHeight();
}
// check for alt + enter
if (IsKeyPressed(KEY_ENTER) && (IsKeyDown(KEY_LEFT_ALT) || IsKeyDown(KEY_RIGHT_ALT)))
{
// see what display we are on right now
int display = GetCurrentMonitor();
if (IsWindowFullscreen())
{
// if we are full screen, then go back to the windowed size
SetWindowSize(screenWidth, screenHeight);
}
else
{
// if we are not full screen, set the window size to match the monitor we are on
SetWindowSize(GetMonitorWidth(display), GetMonitorHeight(display));
}
// toggle the state
ToggleFullscreen();
}
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Press Alt + Enter to Toggle full screen!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment