Drawing directly to an array

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

The offscreen renderer in Mesa (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.

Bob, is there any chance to see your site featuring offscreen OpenGL rendering ?

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.

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

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.

Originally posted by hanskr:
[b]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[/b]
    Mesa 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 . Just change the color and press ‘render’ to get a new image.

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.