每次都要下面两个函数
bool CModelingRenderingView::SetWindowPixelFormat(void)
{
static 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
32,                             // 32-bit color depth
0, 0, 0, 0, 0, 0,               // color bits ignored
0,                              // no alpha buffer
0,                              // shift bit ignored
0,0, 0, 0, 0,                         // no accumulation buffer                 
32,                             // 32-bit z-buffer
0,                              // no stencil buffer
0,                              // no auxiliary buffer
PFD_MAIN_PLANE,                 // main layer
0,                              // 保留结构数
0, 0, 0                         //不支持结构数
}; int m_nPixelFormat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd); if ( m_nPixelFormat == 0 )
{
m_nPixelFormat = 1;
if(DescribePixelFormat(m_pDC->GetSafeHdc(),m_nPixelFormat,sizeof(PIXELFORMATDESCRIPTOR),&pfd)==0)
{
return FALSE;
}
} if ( ::SetPixelFormat(m_pDC->GetSafeHdc(), m_nPixelFormat, &pfd) == FALSE)
{
return FALSE;
}
return TRUE;
}
bool CModelingRenderingView::OpenGLInit(void)
{
//Get a DC for the Client Area
m_pDC = new CClientDC(this);
//Failure to Get DC
if(m_pDC == NULL)
{
MessageBox("Error Obtaining DC");
return FALSE;
}
//Failure to set the pixel format
if(!SetWindowPixelFormat())
{
return FALSE;
}
//Create Rendering Context
m_hGLContext = ::wglCreateContext (m_pDC->GetSafeHdc ());
//Failure to Create Rendering Context
if(m_hGLContext == 0)
{
MessageBox("Error Creating RC");
return FALSE;
}
//Make the RC Current
if(::wglMakeCurrent (m_pDC->GetSafeHdc (), m_hGLContext)==FALSE)
{
MessageBox("Error making RC Current");
return FALSE;
} glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
return TRUE;
}
还要重载onsize ondestroy 等处理一些问题
还要在oncreate里面调用以初始化,每次建一个要用到OpenGL的MFC工程就要配置这么多,能否将这些做成一个称为MFC-OpenGL的模板,每次创建工程的时候直接选取这个模板就可以了? VC2010有这个功能没?