各位大侠好,我是参照NeHe第46课的教程做的,NeHe第46课是在Win32框架中做的,所以我就想把它移植到MFC中去,以便于在MFC中能更好的应用OpenGL,但遇到了问题。问题是:当我再次设置像素时,会失败!!!1、这是设置像素格式的代码:
BOOL COpenGLView::SetupPixelFormat()
{
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
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
};
    int m_nPixelFormat;
//  int m_nPixelFormat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
//  if ( m_nPixelFormat == 0 )
//  {
//  MessageBox("ChoosePixelFormat failed.");
//  return FALSE;
//  }
if (!arbMultisampleSupported)
{
m_nPixelFormat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);

else
{
m_nPixelFormat=arbMultisampleFormat;
}
if ( ::SetPixelFormat(m_pDC->GetSafeHdc(), m_nPixelFormat, &pfd) == FALSE)
{
MessageBox("SetPixelFormat failed.");
return FALSE;
}
return TRUE;
}2、这是在创建窗口并初始化OpenGL的代码:
int COpenGLView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
if(!InitOpenGL())
{
::MessageBox(NULL,"初始化OpenGL失败.","错误",MB_OK|MB_ICONEXCLAMATION);
return -1;
} if(!arbMultisampleSupported && CHECK_FOR_MULTISAMPLE)  //判断是否支持多重采样
{
if (InitMultisample(m_hWnd))//支持多重采样,初始化相关参数
{
                        //当再次初始化OpenGL时,支持多重采样的参数也都初始化成功了,但重新设置像素格式确出错了,请问是怎么回事呢?
InitOpenGL();                         //之前我想重新创建窗口,但也是出错      
//return CView::OnCreate(lpCreateStruct);
}
} SetTimer(1, 20, NULL);
return 0;
}这个问题卡了我好久了,查了很多也问了很多,但都没解决,跪请各位大侠帮帮看看啊,小弟先谢谢啦!