Bill Yates
03-16-2001, 10:21 AM
I am trying to set up a memory dc for rendering to a bitmap. The call to SetPixelFormat() fails does anyone know why? How should it be done?
BOOL COpenGLView::InitialiseOpenGL()
{
m_pDC = new CClientDC(this);
m_pMemDC = new CDC;
m_pMemDC->CreateCompatibleDC(NULL);
SetupPixelFormat();
m_hRC = ::wglCreateContext(m_pMemDC->GetSafeHdc());
::wglMakeCurrent(m_pMemDC->GetSafeHdc(), m_hRC);
::glClearColor(1.0f, 1.0f, 1.0f, 0.0f); // clear color
::glClearDepth(1.0f); // clear depth
::glEnable(GL_DEPTH_TEST); // enable depth testing
return TRUE;
}
BOOL COpenGLView::SetupPixelFormat()
{
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;
int pixelformat;
pixelformat = ::ChoosePixelFormat(m_pMemDC->GetSafeHdc(), &pfd);
ASSERT(::SetPixelFormat(m_pMemDC->GetSafeHdc(), pixelformat, &pfd)); // <<<<< ::SetPixelFormat FAILS
return TRUE;
}
BOOL COpenGLView::InitialiseOpenGL()
{
m_pDC = new CClientDC(this);
m_pMemDC = new CDC;
m_pMemDC->CreateCompatibleDC(NULL);
SetupPixelFormat();
m_hRC = ::wglCreateContext(m_pMemDC->GetSafeHdc());
::wglMakeCurrent(m_pMemDC->GetSafeHdc(), m_hRC);
::glClearColor(1.0f, 1.0f, 1.0f, 0.0f); // clear color
::glClearDepth(1.0f); // clear depth
::glEnable(GL_DEPTH_TEST); // enable depth testing
return TRUE;
}
BOOL COpenGLView::SetupPixelFormat()
{
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;
int pixelformat;
pixelformat = ::ChoosePixelFormat(m_pMemDC->GetSafeHdc(), &pfd);
ASSERT(::SetPixelFormat(m_pMemDC->GetSafeHdc(), pixelformat, &pfd)); // <<<<< ::SetPixelFormat FAILS
return TRUE;
}