Getting a window's pixel format

拈花ヽ惹草 提交于 2019-11-28 11:21:01

问题


I have created an OpenGL application running on Windows. Is there any way I can query information about the pixel format of my current rendering window? (the window was created using the GLFW library)

What I'm interested in:

  • Color bits
  • Depth bits
  • Pixel type
  • etc.

回答1:


I do it like this:

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

Where window_handle is handle of your apps window. If you got access to the hdc directly than you can skip the first line GetDC. This is how I print the info using VCL and my GL engine:

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));

so just use what you got at your disposal for text print. There is a bit more in the pfd structure like bit-shifts, masks etc just inspect it and print what you need.




回答2:


In the GLFW doc you can read about using the OpenGL API directly by for example glGetFramebufferAttachmentParameteriv or glGetIntegerv.




回答3:


You can call glfwGetWin32Window function (from glfw3native.h) and retrieve handle of window.

Get HDC form handle (with GetDC(window_handle) function) Then pass this HDC to GetPixelFormat function and call DescribePixelFormat.

See example of usage GetPixelFormat + DescribePixelFormat here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd318349(v=vs.85).aspx



来源:https://stackoverflow.com/questions/50239798/getting-a-windows-pixel-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!