SetPixelFormat() - failure

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;

}

Hi Bill,

the call to CreateCompatibleDC() creates
a dc that has only one pixel and it’s color organization ist monochrome. This is possibly the error. Why do you create a memory dc?

Greeting Patrick

Thanks markl

I think that you are correct. I have now inserted a SelectObject call with a correctly dimensioned bitmap and that seems to have overcome the problem.

I am creating a memory dc to use as a back buffer to overcome a Windows bug. The bug affects the generic implementation of OpenGL for Windows 2000 when using double-buffering. It causes the right and bottom edges not to be rendered when the window is enlarged.

Thanks again

Bill

[This message has been edited by Bill Yates (edited 03-17-2001).]

Originally posted by Bill Yates:

I am creating a memory dc to use as a back buffer to overcome a Windows bug. The bug affects the generic implementation of OpenGL for Windows 2000 when using double-buffering. It causes the right and bottom edges not to be rendered when the window is enlarged.

I haven’t seen this bug before… Are you sure the problem isn’t just because you are forgetting to use glViewport on the window resize?

Thanks for the suggestion, but no. I certainly wouldn’t exclude the possibility that I’m doing something else wrong. However, please see:- Q272222 - BUG: Clipping Problems with Generic Implementation of OpenGL for Windows 2000

That’s interesting. I run Win2k at work and I’ve only got a Trident for a video card. I am about 99% sure that apps I’ve tested didn’t use hardware acelleration. (I wrote a small app that just checks extensions, etc. and it returns Microsoft GDI Generic as the vendor/renderer for this card.) I’m trying to think if I’ve tested any of the MFC apps I wrote on this machine, since I had it upgraded to 2k. I know my Glut apps work fine, but those wouldn’t be using a child window. I’ll have to pull out one of my old model viewers to try it on.