brandonborkholder / glg2d

Graphics2D wrapper for JOGL
77 stars 31 forks source link

Writing to image #10

Closed it-open closed 11 years ago

it-open commented 11 years ago

Hello! For an special Programm I had to write a completly new User Interface in Java. This is not based on AWT or SWING but draws the Components first in a BufferedImage and then on to the Screen. By now this is fast because i only update the part of the screen that has changed. But when drawing bigger or more complicated Objects it tends to get slower. So I thought I could speed it up with your Library. It Looks very good because I dont need to change all the Code because I can use the GLGraphics2D.

But I only see how to use it in a Panel. I need to draw it Offscreen into a Buffered Image. The same Technique is used on other places to modify Video Content.

Do you see any chance to make an G2DGLImage?

brandonborkholder commented 11 years ago

This library is intended to speed up general Swing drawing when you're displaying it to the user. Drawing into an offscreen buffer, like a texture will be just as fast, but getting that texture back off the video card won't be. Swing will keep everything on the CPU. glg2d will draw it to the video card and then if you want a BufferedImage, you need to read it back and video cards are not optimized to operate like that.

How long does it take you to draw a complex scene to a BufferedImage using Java2D currently?

it-open commented 11 years ago

I have two parts.

  1. I have an Application based on java.awt.Window. On this window I draw the Image of my gui. Every Component of the gui draws an Image. And every Container (like Panel) draws the Components according to their z-order (g.drawimage). When a Component/Panel does not change it will not be redrawn. On the Window only the region which has been changed will be redrawn on the Screen. I use Window because in J7 you can draw a transparent Image/Color on the Window and the Application will be transparent. Every Image also uses RGBA. The Initial Draw of all Compopnents can last up to 300ms for the whole Screen. But goes down on changes to 10ms. This is mainly because the fillrect or worse fillroundrect uses a lot of time. The Image will be drawn Offscreen and every Component keeps it Image and the whole Scene is the displayed on the Screen. I tried with pure OpenGl but the OpenGlCanvas cannot be transparent. (Corrent me if I'm wrong)
  2. I make video Editing. I get a Image from a Video and use this as Base. Then according to some calculations I make diffent Overlays (Transparent Logos, and other Infos). The I save the Image back to a other Stream. More Speed is better but it does not depend on the speed here because the Video Decoding/Encoding takes most of the Time. (I can use normal java Graphics here)
brandonborkholder commented 11 years ago

I finally got around to writing a test that will help you see how to use GLG2D to draw Swing into an OpenGL image or FBO. Here is an example that explains all the steps you need to take https://github.com/brandonborkholder/glg2d/blob/master/src/test/java/org/jogamp/glg2d/examples/FBOExample.java and here is a more useful example of how I applied GLG2D to draw a Swing component into an image and then read the image back again https://github.com/brandonborkholder/glg2d/blob/master/src/test/java/org/jogamp/glg2d/ImageTest.java.

I also think you might want to take a look at Newt for your application. It allows much better control over your windows (transparent windows, undecorated windows, etc). You can still use glg2d to draw Swing into Newt, see https://github.com/brandonborkholder/glg2d/blob/master/src/test/java/org/jogamp/glg2d/examples/NewtExample.java