How do I go full screen without GLUT?


I’m looking for a reliable way to make my OpenGL window full screen (that is, no window borders etc). The FAQ only mentions how to do it using GLUT, which I’m not using. I already have a full working program, so don’t really want to use GLUT just for this one feature, and would GLUT want the whole program to be structured differently anyway? I also heard GLUT doesn’t like multiple OpenGL contexts and sharing of textures etc, which would be a major drawback.

I’m on Windows, and have a couple of MFC apps where I would like to make the OpenGL CView go full screen (and back to windowed later).

What I’m doing currently almost works. In my class derived from CView, I have code something like below to go full screen. It detaches the view from its parent, makes it topMost, and resizes it to cover the screen.

    CRect desktopRect;
    ::GetWindowRect(::GetDesktopWindow(), desktopRect);

    ModifyStyle(0x0, WS_OVERLAPPED);
    ModifyStyleEx(WS_EX_CLIENTEDGE, 0x0);
    wp.showCmd = SW_RESTORE;
    wp.rcNormalPosition = desktopRect;
    SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);

Actually, it does work on my machine, but has some very strange behaviour reported on other machines. On one, there is a dashed line down the left side, a couple of pixels thick, where the expected geometry is not being drawn. In fact, it is rendering geometry from off the OTHER side of the screen (the right side). Similarly there is a few rows (not dashed) of pixels at the top that are showing what should be at the bottom. On another machine it sounds like the whole screen is flashing between old and current buffers.

On both machines it works fine in a window maximized in the usual way.

I read that the GLUT functions create a whole new OpenGL context to cover the screen, which would be slower. Is this necessary for some reason? Why not just use the context I already have?

I also read that they hide all other windows. Should I do that? Presumably I’d have to store their previous states and restore them too.

Any other advice?

With Win32 (not MFC but it may give you a nudge in the right direction) I’d set a style of WS_POPUP and an exstyle of WS_EX_TOPMOST (the latter optional, 0 otherwise). The left/top problem you have is being caused by Windows thinking you still have a frame border on the window.

Thanks for the idea, seems reasonable. However I tried changing to WS_POPUP and removing WS_CHILD, but it created new problems. When I restore the window to its original state, rather than the geometry resizing to fit in the smaller window, it just shows the top left corner of the full-screen view within that smaller view. Even resizing the frame doesn’t fix it. The view’s parent seems to be correctly set back to what it was, but somehow the view isn’t responding to sizing events. Any ideas?