View Full Version : Can OpenGL render directly to a Bitmap in Win32?

01-03-2002, 07:59 AM
The topic is pretty self explaining.
I'm just searching for a function or a way to render directly to a Bitmap or a BYTE array, e.g. BYTE[width * height * bpp];

At the moment I'm just rendering everything and read the pixels form the frame buffer, but I think there is a better way.

Michael Menne

01-03-2002, 08:54 AM
Short answer : No, it can't.
There is also no way to directly access the
backbuffer. You can blit the frontbuffer via
BitBlt into your BMP-DC or can with the help
of glReadPixels read the back/frontbuffer in
all standard GL implementations. If you use
BitBlt there's the problem, that if there's
a window in front of your GL-DC, that the
area overlapping yours would be blitted into
the BMP as well, so the only "clean" way to
do is using glReadPixels...unfortunately this
is the slowest way as well.


01-03-2002, 10:33 AM

I read an article on nvidia.developers.com about using a p(ixel) buffer for offscreen rendering. There is also a sample in their ogl SDK.

Also in the OpenGL SUperBible second edition is an example for offscreen rendering to a bitmap.

When you crate your Opengl RC you use a PIXELFORMATDESCRIPTOR struct there you can specify a PFD_DRAW_BITMAP flag. according with a properly offscreen HDC you could do what you want.
to get details look at the sources above and/or the win32sdk help


Kilam Malik
01-04-2002, 01:13 AM
Yes you can. It works the way ScottManDeath wrote. Just two notes:
- The first solution will not work on every card.
- The second solution will work on every card, but it will not be hardware accelerated! This means it will be slow and the card specific extensions will not work.


[This message has been edited by Kilam Malik (edited 01-04-2002).]