I’ve never printed using Java before so I’m a complete beginner. Could someone point me in the right direction for printing the contents of a GLCanvas window?
Many thanks
I’ve never printed using Java before so I’m a complete beginner. Could someone point me in the right direction for printing the contents of a GLCanvas window?
Many thanks
Use Java’s Robot class to take a screenshot and then print the image. I am sure if you Google a bit you find the copypaste code.
Printing API
http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html
http://www.javaworld.com/javaworld/jw-10-2000/jw-1020-print.html
Robot
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html
Thanks, that will get me going for now, and enable me to learn about printing under Java. However, at some point I will want to be able to generate the appropriate scaled vector image onto the printer directly from the GLCanvas. The images I am generating are Maps using a combination of vector and raster information and are usually printed out at higher quality than a typical display.
In that case you probably need to build yourself a bespoke image into a BufferedImage object and use the graphics context of that to print.
It may mean making your rendering of the data abstract away from jogl.
Kev
I am probably being naive but the last time I had to code up some printing you just obtained the graphics device for the printer and repeated your drawing on it. Does this not work for OpenGL/jogl?
The problem is that the operations you use to draw in JOGL don’t actually take place within a java.awt.Graphics object. Hence you can’t retarget them at the printers graphics object.
You might be able to do something like render into a texture, which is actually a buffered image (like when you take a screenshot of a JOGL render) then draw this buffered image into the printers graphics context.
However, doing this you’d need to make the buffered image that you get JOGL to render into massive to get a decent resolution for your printer. Which many cards might not like to do.
Probably the ideal here (in terms of Java) would be to be able to abstract your rendering process so you could render into GL or into a graphics context.
I could of course be totally wrong and there might be a really cool when of going round the GL or using some extension or other.
Kev
One of my colleagues wrote a tiled rendering routine to do high quality printing. Something along the lines of http://www.mesa3d.org/brianp/TR.html. IIRC each tile is rendered and copied using readPixels.
Unfortunately I can’t give you the code since it’s integrated into our closed, commercial product…
Isn’t this the kind of thing that OpenGL’s feedback mode is designed for?
Bleb, A startlingly obvious suggestion.
OK, it looks like I need to write a print routine that is more complex that I originally anticipated. I’m very suprised at the lack of examples for printing from OpenGL. I’m guessing not many people are interested in high quality printing from it and settle for bitmap copies.
I’m going to add this to my text rendering routine and start compiling a little package of “Java meets OpenGL” facilities on top of jogl. I’ll eventually open source this to some repository but don’t hold your breath as my application comes first.
Thanks for all the help.
bleb: yes and no
We investigated feedback mode initially. The great thing about using feedback mode is that you could generate a vector image from your rendering. Unfortunately you miss some rendering stuff such as texture mapping. I guess it would be possible to do that yourself, but that would be much more work than implementing a tiled rendering routine…
Game programming gems 2 and 4 both have gems on this precise topic by some ATI engineers - basically “how to print poster-quality screenshots”.
The gem in 2 works by stitching tiles together, the one in 4 improves on that by geting rid of some artifacts produced by the one in 2, IIRC.
Both books have source code on the accompanying CD, I believe. I doubt the publisher would take kindly to me copying and pasting their source from the CD to an online forum, but you could ahem go into a book store and read those two gems “just to see if the book would be any use to you”…
Alternatively, if you do much OGL work, you probably want to buy the books anyway, since they’re about 40-60% graphics tricks with OpenGL or maths, all aimed at game develoeprs. Some pretty funky stuff in there.
[quote]One of my colleagues wrote a tiled rendering routine to do high quality printing. Something along the lines of http://www.mesa3d.org/brianp/TR.html. IIRC each tile is rendered and copied using readPixels.
Unfortunately I can’t give you the code since it’s integrated into our closed, commercial product…
[/quote]
Newbie question…
By using TR to render a very large image, is it possible to create a higher-quality page-size (i.e. not poster size)print out than that would be possible by simply taking a snapshot of the required (page) size ?
I recall having used an OpenGL app. long time back, that I think did something similar to TR to create a large image and then converted that to postscript - the resulting (e)ps output was of much better quality than a simple image->ps conversion. I’d be curious if anyone is aware of anything like that !
Thanks
NVaidya: yep that’s the purpose of the tiled rendering. Taking a screen shot gives you an image that is in screen quality i.e. about 72dpi. By rendering the same image at a much higher resolution (in multiple small parts) you can get the same image at printing quality i.e. 300dpi, 600dpi or whatever qulaity you require.
blahblahblah: thanks for the tip. I passed the info on to my coworker. I remember he had to write some code to get line width, label rendering and some other stuff correct. Maybe those articles can make our implementation even better