We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › PGraphics outside of PApplet
Page Index Toggle Pages: 1
PGraphics outside of PApplet? (Read 927 times)
PGraphics outside of PApplet?
Dec 23rd, 2008, 1:48am
 
I'm working on a system in Java to control a series of lights which will end up displaying values based on Processing animations. I'm already using Processing for the GUI, but we also need to be able to create PGraphics which can be drawn to off screen, and their raster can be sent to the lighting hardware.

I'm using the GUI instance of PApplet and returning a PGraphics object to the main conductor code, which then provides the instance to the show which will be drawing to it.

The issue I'm having is that several things are not working as expected such as:
- drawing anything with a stroke causes a null pointer exception inside PGraphics2D's line drawing methods.
- using translate as a method of the PGraphics instance simply isn't working (though when I use the same code in the Processing IDE it works perfectly)
- alpha values don't seem to make a difference

Has anyone else used PGraphics in a Java program outside the context of the PApplet?
Re: PGraphics outside of PApplet?
Reply #1 - Dec 23rd, 2008, 4:48pm
 
You can send a BufferedImage, perhaps, it is a standard Java class.
Example to get a BI from a PImage:
Code:
  BufferedImage bufimg = new BufferedImage(
     smallImage.width, smallImage.height,
     smallImage.format == ARGB ?
         BufferedImage.TYPE_INT_ARGB :
         BufferedImage.TYPE_INT_RGB);
 bufimg.setRGB(0, 0, smallImage.width, smallImage.height,
     smallImage.pixels, 0, smallImage.width);
Re: PGraphics outside of PApplet?
Reply #2 - Dec 24th, 2008, 8:54pm
 
I'm not sure that's quite what I'm looking for...

The idea of passing the PGraphic is to allow all of the same easy processing drawing functions. Once each frame is drawn we're taking the PImage from it and converting it to a string of bytes sent to the light controller. This all works just fine. Even a lot of the drawing methods work within the PGraphic.

The problem is there is some mysteriously missing functionality which I was really hoping to use... and I'm wondering if there is more of a dependency PGraphics has on running within a PApplet instance (such as using translate, or drawing lines) which just don't work when the PApplet passes a PGraphic to a parent object.
Re: PGraphics outside of PApplet?
Reply #3 - Dec 24th, 2008, 9:58pm
 
I read through the createGraphics documentation a little bit more and it seems the P2D implementation isn't finished. I tried implementing JAVA2D and that just crashed it, but P3D seems to translate properly and draw lines properly as well. I'm still wondering about implementing transparency, but I'm back on the right track.
Page Index Toggle Pages: 1