SWT+lwjgl+OpenGL: How to render to an offscreen image?

Started by carolus09, August 27, 2006, 11:03:57

Previous topic - Next topic

carolus09

I am using Eclipse SWT (3.2) with LWJGL. The OpenGL scene is drawn on a component which is part of a window. Now I would like to render the scene to an offscreen image with arbitrary resolution in order to save it as a file (for example *.png).
Any hints or even portions of code would be greatly appreciated.

Matzon


carolus09

I tried the example code you pointed to. With small views this works, but when the window grows I get an exception (access violation) by the Java VM.
What I really wanted is to render directly to an offscreen image, because I want the image to have a higher resolution than that of the screen.

Matzon

courtesy of irc://irc.freenode.net/lwjgl :)
Quote[19:38:27] <FN~DarkProphet> FBO with RenderBuffer
[19:38:35] <FN~DarkProphet> then readback from the RB
[19:39:32] <Mazon> isn't fbo's new gfx cards only ?
[19:40:07] <FN~MatthiasM> of course - but it's too complicated for just a screen shot
[19:40:20] <FN~MatthiasM> but if you want to render a movie then you could use RBO
[19:40:22] <FN~DarkProphet> Mazon: yeah, but it supports rendering to an offscreen buffer, but it should be rolled back to older HW
[19:40:31] <FN~DarkProphet> most NV cards/Geforce have it
[19:40:59] <FN~DarkProphet> the 5200 is a pretty old card, yet it has FBO support
[19:41:08] <FN~DarkProphet> its only those damed Intels and ATIs that are pretty crap

carolus09

thank you, but I have to code things without relying on extensions like fbo.

napier

How about using a pbuffer?   I think you'd find pretty broad support for that feature.  I've saved large images from a pbuffer (4096 pixels wide).

Also you may need to increase the memory used by your JVM if you want to save large images.  I use:     java -Xms360m -Xmx360m  ....
and of course your graphics card needs to have enough memory for a large pbuffer if you go that route.

And finally you can create really huge images by using glFrustum() to render the scene a piece at a time, save each screen image to a file, and then stitch the files together.  It takes some work but I've used this technique to produce large hi-res prints from scenes.  If you want code I can dig it up.
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl