PDA

View Full Version : Drawing directly to an array



hanskr
07-14-2004, 05:09 AM
Hi,
I have an array representing a raw image (RGB).

I need to draw some OpenGL graphics on this image without opening a window.

Is there a way to let OpenGL work directly on a buffer representing an image?

Thanks!
Hans Kristian

Bob
07-14-2004, 05:20 AM
The offscreen renderer in Mesa (http://www.mesa3d.org) (OSMesa) works exactly like that. You allocate a buffer, give it to OpenGL when creating the rendering context, and everything is drawn directly into that buffer. No need for a window.

I used it for my webserver to show dynamically generated images based, say, on parameters passed from a webpage. Works great.

ZbuffeR
07-14-2004, 10:38 AM
Bob, is there any chance to see your site featuring offscreen OpenGL rendering ?

Bob
07-14-2004, 03:06 PM
Sadly, no. I had it for experimenting, and I removed it while clearing the directory structure quite some time ago since I had no more use for it. But I can start looking into making a new one for fun, I got some time to spare so at least I will have something to do.

hanskr
07-15-2004, 02:49 AM
Thanks for the reply, Bob. I would prefer to do this without the use of any extra modules / installs. If that is not possible to do in "bare" OpenGL, it is better I just open a minimized window or something, as I'm not in a position to introduce extra dependancies to the projct.

- Hans Kristian

Kilam Malik
07-15-2004, 02:59 AM
Of course you can do this with standard OpenGL. You just need different parameters for the ChoosePixelFormat. As the HDC parameter you pass the HDC of a bitmap, not a window. As the dwFlags parameter you pass the PFD_DRAW_TO_BITMAP instead of PFD_DRAW_TO_WINDOW.

You will _not_ get hardware accelleration here (which means also no extensions). If you want that, you need to draw in a window and read the bitmap from there. But be careful: The window must be completely visible. Otherwise the overlapped or invisible regions will not get rendered.

Update: Just read your post again... to answer your post correctly: It is not possible to draw in an array, but in an offscreen bitmap as described above.

Kilam.

Bob
07-15-2004, 10:16 AM
Originally posted by hanskr:
Thanks for the reply, Bob. I would prefer to do this without the use of any extra modules / installs. If that is not possible to do in "bare" OpenGL, it is better I just open a minimized window or something, as I'm not in a position to introduce extra dependancies to the projct.

- Hans KristianMesa is an implementation of OpenGL, just like the defualt one that ships with Windows. You don't add anything, or makes any modifications, to that implementation, you replace it with a completely different, stand alone, implementation. Mesa IS plain OpenGL. Ultimately, nothing shouldn't have to change in the code (except where you create the rendering context, a line or two) to make it work with Mesa instead. It may even be possible to just add a DLL-file (assuming Windows) and don't change the code at all, not even recompile it. For offscreen rendering, you just use a different glue-layer; OSMesa instead of wgl.

But if you want to drop an, in my oppinion, perfect solution for offscreen rendering, almost without any modifications to the code just because you dont't want to use a different implementation of OpenGL, then I'm not going to stop you :rolleyes:

By the way, I maganed to dig up the old program I had to generate images dynamically from an old backup. Thought it was lost, but obviously not. Clicky (http://www.e98.org/bunny/index.pl) . Just change the color and press 'render' to get a new image.

endash
07-16-2004, 12:18 PM
There are ways to get off-screen render contexts, but I think you would still need to copy the resulting image from that context into your array. glReadPixels I think is the function you'd want for that.