Thread: OpenGL Fullscreen

  1. #1
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    OpenGL Fullscreen

    I modified an OpenGL program I made so I could toggle fullscreen.

    It seems to go into fullscreen just fine, but when I try to toggle back, it remains fullscreen and it just shows the titlebar. How can I get it to convert back?

    Code:
    HWND CreateMyWindow(LPSTR strWindowName, int width, int height, HINSTANCE hInstance, bool fullscreen)
    {
      
        HWND     hWnd;
        WNDCLASS wc;
    
        DWORD dwExStyle;
        DWORD dwStyle;
    
        RECT rWindow;
    
        memset(&wc, 0, sizeof(WNDCLASS));
        wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
        wc.lpfnWndProc   = WinProc;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_3DSHADOW + 1);
        wc.lpszClassName = "Chip8";
    
        RegisterClass(&wc);
    
        g_hInstance = hInstance;
    
        rWindow.left   = 0;
        rWindow.right  = width;
        rWindow.top    = 0;
        rWindow.bottom = height+15;
        
        if(fullscreen) {
            
            DEVMODE dmScreenSettings;
            memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
            
            dmScreenSettings.dmSize         = sizeof(dmScreenSettings);		
    	dmScreenSettings.dmPelsWidth	= width;				
    	dmScreenSettings.dmPelsHeight	= height;			  
    	dmScreenSettings.dmBitsPerPel	= 16;
    	dmScreenSettings.dmFields       = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    		
    	ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
      	
        }		
        
        if(fullscreen) {
            
            dwExStyle = WS_EX_APPWINDOW;
            dwStyle   = WS_POPUP;
            ShowCursor(FALSE);
            
        }        
        
        else {
        
            dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
            dwStyle = WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU;
            
        }    
    
        AdjustWindowRectEx(&rWindow, dwStyle, FALSE, dwExStyle);
    
        hWnd = CreateWindowEx(dwExStyle, "Chip8", strWindowName, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
                              0, 0, rWindow.right - rWindow.left, rWindow.bottom - rWindow.top, NULL, NULL, hInstance, NULL);
    
        if(!hWnd) return NULL;
    
        ShowWindow(hWnd, SW_SHOWNORMAL);
        UpdateWindow(hWnd);
    
        SetFocus(hWnd);
    
        return hWnd;
        
    }
    Last edited by Vicious; 09-07-2004 at 12:33 AM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    When you switch back to a window you'll need to restore the desktop settings with
    Code:
    ChangeDisplaySettings(0,0);
    See description for lpDevMode in ChangeDisplaySettings.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-12-2006, 08:42 PM
  2. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM