PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
24, // Select Our 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, // Accumulation Bits Ignored
32, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};//在DC中选择合适的像素格式并返回索引号
int pixelFomat;
pixelFomat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
if (pixelFomat == 0)
{
MessageBox(L"选择像素模式失败!", L"设置像素格式", MB_ICONERROR);
return FALSE;
}
//设置指定像素格式
if(::SetPixelFormat(m_pDC->GetSafeHdc(), pixelFomat, &pfd) == FALSE)
{
MessageBox(L"设置像素模式失败!", L"设置像素格式", MB_ICONERROR);
return FALSE;
}
《高效学习OpenGL》之 openGL设置窗口像素格式