I'd like to use OpenGL to draw directly to a .NET System::Drawing::Bitmap (C++/CLI). It seems like it should work like this:
char buf[48];
ZeroMemory( &buf, sizeof(buf));
System::Drawing::Bitmap bmp(
4,
4,
12,
Imaging::PixelFormat::Format24bppRgb,
(System::IntPtr)buf);
Graphics^ g = Graphics::FromImage(%bmp);
HDC local_hdc = (HDC)((void*)g->GetHdc());
HGLRC local_hrc = wglCreateContext( local_hdc );
if(!wglMakeCurrent( local_hdc, local_hrc ))
ShowError();
//Draw something with OpenGL ...
g->ReleaseHdc((IntPtr)((void*)local_hdc));
//Do something with the bitmap ...
But wglMakeCurrent fails with "The pixel format is invalid".
"Of course!" I think. "I just need to set the pixel format of the bitmap in such a way that OpenGL can render to it!"
Sadly, if I use the above Bitmap constructor, I'm limited to an enum of canned pixelformats, rather than a struct holding a bunch of attributes that I can OR together. And I don't think it's possible to set the pixel format after the fact.
Anyway, this way of doing things would be prettier than using a bunch of Win32 calls to make a Device-Independent Bitmap, but the canned pixel formats seem to omit any sort of GL-enabled anything, and I just fail. Can you succeed?