This is driving me nuts… I hope someone can help me out with this… btw: i’m a newbie to opengl.
Here’s my snippet…
DWORD lastError;
HWND hWnd = this->getRenderHWND();
HDC hDC = GetDC(hWnd);
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat = ChoosePixelFormat( hDC, &pfd );
BOOL sret = SetPixelFormat( hDC, iFormat, &pfd );
if( FALSE == sret ) {
lastError = GetLastError();
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
lastError,
0,
(LPTSTR) &lpMsgBuf,
0,
NULL
);
debug(“SetPixelFormat error %u - %s”, lastError,
(char*)lpMsgBuf);
LocalFree( lpMsgBuf );
}
The debug statement prints:
SetPixelFormat error 3221684230 - Access is denied
So I figure I have atleast one problem, that SetPixelFormat is returning false. The other problem could be my FormatMessage is incorrect, thus giving a bogus error code and message. In any case, any idea why SetPixelFormat is failing? btw: I know the original HWND is valid, i print it out and compared it to the value as found in Spy++ and I did check to make sure GetDC is returning non-null.
One more piece of info. The handle to the window onto which I would like to draw belongs to a different application. Is that a problem?
Thanks,
Paul