Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

NateRedding

Toggling Fullscreen & Windowed

This topic is 5880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone have a working example of how to toggle between full screen and windowed modes in OpenGL? I''ve seen things that toggle before really initializing anything using ChangeDisplaySettings(). I figured I should be able to just use that to switch between them normally, but couldn''t get it to work. It seems to make the change successfully, then just shuts down. Actually, I guess this isn''t really even OpenGL code, just windows code. Any help would be appreciated. Thanks! Nate

Share this post


Link to post
Share on other sites
Advertisement
hi nate

that''s the code i am using in my game...


  
void SetDisplayMode (int Width, int Height, int BBP, bool Fullscreen, int Frequency)
{
PIXELFORMATDESCRIPTOR pfd = {0};
INT ipf;
DWORD exstyle,style;
RECT r;

if (wndMain)
{
DestroyWindow(wndMain);
wglMakeCurrent(dcMain,0);
wglDeleteContext(rcMain);
}

if (Fullscreen)
{
DEVMODE dm;

memset(&dm,0,sizeof(DEVMODE));

dm.dmSize = sizeof(DEVMODE);
dm.dmPelsWidth = Width;
dm.dmPelsHeight = Height;
dm.dmBitsPerPel = BBP;
dm.dmDisplayFrequency = Frequency;
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;

if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
MessageBox(0,"Display mode not supported","Error", MB_ICONSTOP);
Fullscreen = false;
}
}

exstyle = Fullscreen ? WS_EX_APPWINDOW : 0;
style = Fullscreen ? WS_POPUP | WS_VISIBLE : WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

r.left = 0;
r.top = 0;
r.right = Width;
r.bottom = Height;

AdjustWindowRectEx(&r,style,0,exstyle);

wndMain = CreateWindowEx(exstyle,"__glwindow","GLWindow",style,0,0,r.right,r.bottom,0,0,GetModuleHandle(0),0);
dcMain = GetDC(wndMain);

pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.nVersion = 1;

if (BBP == 32)
{
pfd.cDepthBits = 16;
pfd.cColorBits = 32;
pfd.cRedBits = 8;
pfd.cGreenBits = 8;
pfd.cBlueBits = 8;
pfd.cAlphaBits = 8;
}
else if (BBP == 16)
{
pfd.cDepthBits = 16;
pfd.cColorBits = 16;
pfd.cRedBits = 5;
pfd.cGreenBits = 6;
pfd.cBlueBits = 5;
pfd.cAlphaBits = 0;
}

ipf = ChoosePixelFormat(dcMain,&pfd);
SetPixelFormat(dcMain,ipf,&pfd);
rcMain = wglCreateContext(dcMain);
wglMakeCurrent(dcMain,rcMain);

glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(60,(float)Width/(float)Height,0.1,1000);
}

Share this post


Link to post
Share on other sites
Does anyone else notice that things slow down considerably in full-screen mode as opposed to partial screen?
Just something that I observed happens in my OpenGL programs.

TommyB

Share this post


Link to post
Share on other sites
hmm could be that nasty "vertical retrace" monster. Can you disable it on your video hardware? (On my NVidia card, I can disable it via the display->properties->advanced control panel applet)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!