Skip to content

Instantly share code, notes, and snippets.

@JeffM2501
Created March 7, 2021 17:32
Show Gist options
  • Save JeffM2501/6e4630a0e34c0c7dddf066f7192e342d to your computer and use it in GitHub Desktop.
Save JeffM2501/6e4630a0e34c0c7dddf066f7192e342d to your computer and use it in GitHub Desktop.
Raylib fullscreen toggle 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
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
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
{
// 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