Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
905 views
in Technique[技术] by (71.8m points)

c++ - Getting a window's pixel format

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...