Rendering directly to bitmaps.

I need to use OpenGL to render directly to a bitmap. I make the bitmap with CreateBitmap(), and then select it with a DC. How do I set up OpenGL to render through the DC and onto the bitmap?

Thanks for any help.

you just do like in a window : Create the DC, create a RC and DRAW!!

Rendering to a bitmap requires the PIXELFORMATDESCRIPTOR dwFlags field to have PFD_DRAW_TO_BITMAP set.
If you user ChoosePixelformat() make sure you really got one with that flag set with DescribePixelformat() afterwards.

Hardware accelerated formats usually don’t support PFD_DRAW_TO_BITMAP, so expect to end up with MS GDI software OpenGL implementation.

IMHO, you’ll ALWAYS end up with MS generic implementation.

The easiest way is:

  • create normal window, DC and RC
  • render to window
  • glReadPixels to your bitmap
  • free RC, DC and destroy window

This gives you opportunity to accelerate rendering AND to use M$ GDI with too large bitmaps.

Originally posted by ruslan_abdikeev:
[b]
The easiest way is:

  • create normal window, DC and RC
  • render to window
  • glReadPixels to your bitmap
  • free RC, DC and destroy window
    B]

Problem is, that the window has to be visible to render to a bitmap. If you want to take a picture of your screen, than its fine to do it this way. If you want to write out a bitmap with a specific size and it should not be visible to the user, than you have to render to a bitmap.

I think superbible 2nd edition chapter 18, covers this…

Kilam Malik: Yes, you’re right

Why don’t you use WGL_ARB_pbuffer extension? http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_pbuffer.txt