【问题标题】:OpenGL exclusive mode fullscreenOpenGL独占模式全屏
【发布时间】:2014-07-14 23:48:40
【问题描述】:

DirectX 允许应用程序独占一个 GPU 和监视器,它的内容被发送到。这称为全屏。使用 OpenGL 时,使用ChangeDisplaySettings(&dv, CDS_FULLSCREEN) 激活全屏。但是,这样做的结果是“假”全屏 - 全屏窗口。两者的行为方式存在一些差异,尤其是在 alt-tab 键失焦时。

有没有办法像 DirectX 那样只使用 Win32 api 和 OpenGL 来创建全屏窗口,或者这是 DirectX 独有的功能?

【问题讨论】:

    标签: c++ windows winapi opengl


    【解决方案1】:

    如果你愿意让 GLUT 为你做窗口任务,你可以看这里:Full screen in openGL

    如果你想自己进入WIN32细节,你可以这样做:

    #include <stdlib.h>
    
    #include <Windows.h>
    
    #include "glew.h"
    #include <gl/GL.h>
    #include <gl/GLU.h>
    
    
    int main()
    {
        HWND hwnd;
        HDC hdc;
        int pixelFormat;
        PIXELFORMATDESCRIPTOR pfd;
    
        // First create the full screen window
        hwnd = CreateWindowEx(
            0 ,"STATIC","", WS_VISIBLE|WS_EX_TOPMOST,
            0,0,640,480, 0, 0, GetModuleHandle(NULL), 0
        );
        WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
        DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
        MONITORINFO mi = { sizeof(mi) };
        if (
            GetWindowPlacement(hwnd, &g_wpPrev) &&
            GetMonitorInfo(MonitorFromWindow(hwnd,MONITOR_DEFAULTTOPRIMARY), &mi)
        ) {
            SetWindowLong(hwnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
            SetWindowPos(
                hwnd, HWND_TOP,
                mi.rcMonitor.left, mi.rcMonitor.top,
                mi.rcMonitor.right  - mi.rcMonitor.left,
                mi.rcMonitor.bottom - mi.rcMonitor.top,
                SWP_NOOWNERZORDER | SWP_FRAMECHANGED
            );
        }
    
        // Describe the pixel format
        memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
        pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
        pfd.nVersion = 1;
        pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
        pfd.iPixelType = PFD_TYPE_RGBA;
        pfd.cColorBits = 32;
        pfd.cDepthBits = 16;
        pfd.iLayerType = PFD_MAIN_PLANE;
    
        // Create the device context and rendering context
        hdc = GetDC(hwnd);
        pixelFormat = ChoosePixelFormat(hdc,&pfd);
        SetPixelFormat(hdc,pixelFormat,&pfd);
        HGLRC rendering_context = wglCreateContext(hdc);
        BOOL rc = wglMakeCurrent(hdc, rendering_context);
        GLenum err = glewInit();
        if (GLEW_OK != err) { /*do something*/ }
    
        // Paint the back buffer red
        glClearColor(1,0,0,0);
        glClear(GL_COLOR_BUFFER_BIT);
        glFlush();
    
        // Show on screen
        rc = SwapBuffers(hdc);
    
        while (1)
        {
            // Do something ...
        }
    
        return 0;
    }
    

    【讨论】:

    • 这是一个改进(窗口总是在其他窗口的顶部),但是当任务栏出现在全屏窗口的前面时,alt-tab 的行为仍然很奇怪。这也是 glut 的作用吗?
    • 您使用的是什么操作系统?我使用的是 windows 8,任务栏问题没有重现。
    • 8.1 - 我在这里看到了一个主题。我刚刚问了另一个涉及无法重现的窗口系统的问题。和我的机器有关系吗?
    猜你喜欢
    • 2014-05-18
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多