選擇和設定Best-Match像素格式
本主題說明將裝置內容與像素格式相符的程式。
若要取得裝置內容與像素格式的最佳相符專案
在 PIXELFORMATDESCRIPTOR 結構中指定所需的像素格式。
-
ChoosePixelFormat函式會傳回像素格式索引,然後您可以傳遞至SetPixelFormat,將最佳像素格式設定為裝置內容的目前像素格式。
下列程式碼範例示範如何執行上述步驟。
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
HDC hdc;
int iPixelFormat;
// get the device context's best, available pixel format match
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
// make that match the device context's current pixel format
SetPixelFormat(hdc, iPixelFormat, &pfd);