Sign in to follow this  
exorcist_bob

OpenGL switching between fullscreen and windowed

Recommended Posts

Hello, How can I switch between these two modes? The only way that I know of is destroy/recreate the window, since opengl requires some prelim stuff before window creation. Thanks, exorcist_bob

Share this post


Link to post
Share on other sites
Hmmmmm,Have you read the first Nehe tutorial? It has code that allows you to switch mode.

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01

Share this post


Link to post
Share on other sites
Quote:
Original post by exorcist_bob
At runtime. For instance I have it in windowed mode, and when I press F2, it switches to fullscreen and vice-versa.


That is what lesson one does, just take a look in the game loop and you would have seen it, because what it does is inside the gameloop it destroys the current window and creates a new one fast while switching screenmodes. After this the game continues with the new hDC/hGLRC. So you do have to kill your window first, but it switches immediately to the new fullscreen window.


if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode

// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's OpenGL Framework",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}


Greetings.

Share this post


Link to post
Share on other sites
if you are using Win32 for your windowing code and you don't change resolution you can just call the SetScreenMode() function (iirc, you might want to check that, it's in the NeHe code), you might want to change and update the window's style as well to gain/lose the window dectorations

Share this post


Link to post
Share on other sites
Quote:
Original post by Limitz
Quote:
Original post by exorcist_bob
At runtime. For instance I have it in windowed mode, and when I press F2, it switches to fullscreen and vice-versa.


That is what lesson one does, just take a look in the game loop and you would have seen it, because what it does is inside the gameloop it destroys the current window and creates a new one fast while switching screenmodes. After this the game continues with the new hDC/hGLRC. So you do have to kill your window first, but it switches immediately to the new fullscreen window.


if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode

// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's OpenGL Framework",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}


Greetings.


Whoa, I didn't even see that there. Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this