Thread: OpenGL: Changing the size of the window disables rendering for a while

  1. #1
    Registered User
    Join Date
    May 2014
    Posts
    121

    OpenGL: Changing the size of the window disables rendering for a while

    I have a handler in the main window callback for switching to "fake" fullscreen whenever I release the left mouse button (it doesn't do much else other than forward all other events to DefWindowProc). The fullscreen function looks like this (all the error checking has been removed to make it easier to read):
    Code:
    bool set_fullscreen(HWND window_handle)
    {     
        DWORD current_window_style = GetWindowLongPtr(window_handle, GWL_STYLE);
        DWORD current_extended_window_style = GetWindowLongPtr(window_handle, GWL_EXSTYLE);
    
    
        HMONITOR monitor = MonitorFromWindow(window_handle, MONITOR_DEFAULTTONEAREST);
        MONITORINFO monitor_info;
        monitor_info.cbSize = sizeof(MONITORINFO);
        GetMonitorInfo(monitor, &monitor_info)
    
    
        DWORD new_window_style = current_window_style & ~WS_OVERLAPPEDWINDOW;
        SetWindowLongPtr(window_handle, GWL_STYLE, new_window_style);
    
    
        DWORD new_extended_window_style = current_extended_window_style & ~(WS_EX_DLGMODALFRAME | WS_EX_OVERLAPPEDWINDOW | WS_EX_STATICEDGE);
        SetWindowLongPtr(window_handle, GWL_EXSTYLE, new_extended_window_style);
    
    
        SetWindowPos(window_handle,
                     HWND_TOP,
                     monitor_info.rcMonitor.left,
                     monitor_info.rcMonitor.top,
                     monitor_info.rcMonitor.right - monitor_info.rcMonitor.left,
                     monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top,
                     SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
    
    
        return true;
    }
    The window gets resized without errors but all the OpenGL calls end up getting ignored until I change the window size again. Even doing something as simple as clearing the background and then calling SwapBuffers doesn't do anything.

    This is the simple draw function I'm using to test things with and it just sets the background to a certain color:
    Code:
    void draw(HDC device_context_handle){
        if (!device_context_handle)
        {
            puts("Invalid argument: device_context_handle");
            return;
        }
    
    
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
        glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        SwapBuffers(device_context_handle);
    }
    I'm normally doing extensive error checking so it's not a problem with errors being ignored. Am I supposed to do something with the device context/OpenGL context after resizing the window? The strange thing is that the draw command works whenever I change the window size back to its original size.

    I've had this exact same issue with both SDL and GLFW so I'm not sure if it's a problem with my computer or I just have the wrong assumptions about how things work.

  2. #2
    Registered User
    Join Date
    May 2014
    Posts
    121
    It turns out that calling the draw function in the WM_WINDOWPOSCHANGED case label works (although with a bit of flickering) but it doesn't work if I change the label to WM_SIZE. I have no idea what's going on.

  3. #3
    Registered User
    Join Date
    May 2014
    Posts
    121
    It seems to be an issue with switching to fullscreen mode. Changing the window size to anything but the exact dimensions of the screen resolution doesn't produce this bug. You can bypass the fullscreen triggering code entirely by setting the fullscreen window height to one more pixel than the actual screen resolution and that also removes the flickering that happens due to the DWM (desktop window manager) turning off Aero or whatever Windows 8 uses.

    I don't understand why the first SwapBuffers command after switching to fullscreen is ignored though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GLX/X11 Changing the rendering resolution
    By Coffee_and_Code in forum Linux Programming
    Replies: 2
    Last Post: 07-27-2013, 06:36 PM
  2. Replies: 1
    Last Post: 01-13-2011, 09:46 PM
  3. openGL rendering
    By zacs7 in forum Game Programming
    Replies: 11
    Last Post: 10-24-2007, 03:58 PM
  4. OpenGL rendering problem
    By JJFMJR in forum Game Programming
    Replies: 8
    Last Post: 08-31-2007, 07:26 PM
  5. Changing Window Size
    By outerspace in forum C++ Programming
    Replies: 3
    Last Post: 11-23-2005, 01:07 PM