brandonborkholder / glg2d

Graphics2D wrapper for JOGL
77 stars 31 forks source link

Using it with BufferedImage #26

Open rmafort opened 10 years ago

rmafort commented 10 years ago

Hello, I have an application which works with BufferedImage, adding "layers" and then obtaining the final image using the following code:

BufferedImage buffer; // Current image Graphics2D g2d = buffer.createGraphics() // Get a Graphics2D to work on this image

And then I work on it adding layers, and then dispose the Graphics2D. I do so on each layer, until I get the final image.

Is there a way to I have use the benefits from GLG2D? Since I can't even cast the Graphics2D obtained to yours GLGraphics2D. Or there is another way to work with images that I don't know yet? Thanks in advance!

brandonborkholder commented 10 years ago

You need to draw your scene into a GLPBuffer or an FBO, some offscreen drawable. Then use the JOGL com.sun.opengl.util.Screenshot class to dump the FBO to a BufferedImage.

cmadsen commented 3 years ago

Is it possible to get an example of how to do the equivalent of:

        GraphicsEnvironment ge = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                .getDefaultConfiguration();
        BufferedImage image = gc.createCompatibleImage(200,
                200, Transparency.BITMASK);
                Graphics2D g = image.createGraphics();
                g.fillRect(10, 10, 100, 100);

with glg2d, i.e., so g in the above code becomes a GLGraphics2D?