typedef struct tagPIXELFORMATDESCRIPTOR
{ // pfd
WORD nSize; //结构大小: sizeof(PIXELFORMATDISCRIPTOR)
WORD nVersion; //版本: 1
DWORD dwFlags; //像素缓冲区属性
BYTE iPixelType; //像素格式
BYTE cColorBits; //颜色缓冲区中位平面的数量
BYTE cRedBits; //用多少位表示红色
BYTE cRedShift; //红色位的移位计数
BYTE cGreenBits;
BYTE cGreenShift;
BYTE cBlueBits;
BYTE cBlueShift;
BYTE cAlphaBits;
BYTE cAlphaShift;
BYTE cAccumBits; //积累缓冲区位数
BYTE cAccumRedBits; //积累缓冲区中红色的位数
BYTE cAccumGreenBits;
BYTE cAccumBlueBits;
BYTE cAccumAlphaBits;
BYTE cDepthBits; //深度缓冲区位数
BYTE cStencilBits; //模板缓冲区位数
BYTE cAuxBuffers; //多少个辅助缓冲区
BYTE iLayerType; //过时或忽略
BYTE bReserved; //上层或下层平面的数量
DWORD dwLayerMask; //过时或忽略
DWORD dwVisibleMask; //下平面的透明颜色
DWORD dwDamageMask; //过时或忽略
} PIXELFORMATDESCRIPTOR;
//************************************************************************
//设置窗口像素格式
//************************************************************************
GLuint PixelFormat; // Holds The Results After Searching For A Match
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
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
32, // 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
16, // 16Bit Z-Buffer (Depth Buffer)
1, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
if (!PixelFormat=ChoosePixelFormat(m_hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
MessageBox("Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if(!SetPixelFormat(m_hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
{
MessageBox("Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}