【问题标题】:Getting a window's pixel format获取窗口的像素格式
【发布时间】:2018-05-09 16:08:30
【问题描述】:

我创建了一个在 Windows 上运行的 OpenGL 应用程序。有什么方法可以查询当前渲染窗口的像素格式信息吗? (窗口是使用 GLFW 库创建的)

我感兴趣的:

  • 颜色位
  • 深度位
  • 像素类型

【问题讨论】:

  • “像素类型”是什么意思?

标签: c++ windows opengl glfw


【解决方案1】:

我是这样做的:

int i;
HDC hdc;
PIXELFORMATDESCRIPTOR pfd;
hdc = GetDC(window_handle);                     // get device context
i=GetPixelFormat(hdc);                          // pixel format descriptor index
DescribePixelFormat(hdc,i,sizeof(pfd),&pfd);    // format from index

window_handle 是您的应用程序窗口的句柄。如果您可以直接访问hdc,则可以跳过第一行GetDC。这就是我使用 VCL 和我的 GL 引擎打印信息的方式:

scr.text(AnsiString().sprintf("color: %i bit R%i G%i B%i A%i",pfd.cColorBits,pfd.cRedBits,pfd.cGreenBits,pfd.cBlueBits,pfd.cAlphaBits));
scr.text(AnsiString().sprintf("accum: %i",pfd.cAccumBits));
scr.text(AnsiString().sprintf("depth: %i",pfd.cDepthBits));
scr.text(AnsiString().sprintf("stenc: %i",pfd.cStencilBits));
scr.text(AnsiString().sprintf("auxil: %i",pfd.cAuxBuffers));

所以只需使用您可以使用的文本打印。 pfd 结构中还有更多内容,例如位移、掩码等,只需检查它并打印您需要的内容即可。

【讨论】:

    【解决方案2】:

    GLFW doc 中,您可以通过例如glGetFramebufferAttachmentParameterivglGetIntegerv 直接阅读有关使用OpenGL API 的信息。

    【讨论】:

      【解决方案3】:

      您可以调用 glfwGetWin32Window 函数(来自 glfw3native.h)并检索窗口句柄。

      获取 HDC 表单句柄(使用 GetDC(window_handle) 函数)然后将此 HDC 传递给 GetPixelFormat 函数并调用 DescribePixelFormat。

      在此处查看 GetPixelFormat + DescribePixelFormat 的用法示例: https://msdn.microsoft.com/en-us/library/windows/desktop/dd318349(v=vs.85).aspx

      【讨论】:

        猜你喜欢
        • 2021-09-15
        • 2015-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-04
        • 1970-01-01
        相关资源
        最近更新 更多