获取窗口的像素格式 [英] Getting a window's pixel format
问题描述
我创建了一个在Windows上运行的OpenGL应用程序.有什么方法可以查询有关当前渲染窗口的像素格式的信息? (该窗口是使用GLFW库创建的)
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)
我感兴趣的是
- 颜色位
- 深度位
- 像素类型
- 等
推荐答案
我这样做是这样的:
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 引擎打印信息的方式:
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));
因此,只需使用您可以支配的文字打印即可. pfd
结构中还有更多内容,例如移位,掩码等,只需对其进行检查并打印所需的内容即可.
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.
这篇关于获取窗口的像素格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!