Re: Problem with off-screen render

Bill,

Here's a hack that works -- read an image, and use the
Graphics2D from that Image to get a GraphicsConfiguration.
Perhaps, you can change one of the APIs to accept
such a graphics configuration from the application,
since you probably don't want the VisAD classes reading local
files :)

Thanks for your help.

Lak


// run as:     java -Djava.awt.headless=true OffscreenImage

import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;

class OffscreenImage
{
 public static void main(String[] args) throws Exception
 {
    BufferedImage template = ImageIO.read( new File("test.jpg") );
    Graphics2D g = template.createGraphics();
    GraphicsConfiguration config = g.getDeviceConfiguration();
    if ( config != null )
       System.out.println( "Got valid GraphicsConfiguration" );
 }
}





Bill Hibbard wrote:

Hi Lak,

On Fri, 27 Aug 2004, Valliappa Lakshmanan wrote:

Thanks, Ugo. I was not aware that you could specify a headless
environment that way.
I think this is the right way to go, because ultimately, I want to
create images
using VisAD within a servlet, and servlets are headless.

I added -Djava.awt.headless=true to the invocation of the java VM
when I ran my test program.
I now get a InitializerException thrown from DisplayImplJ3D.initialize()
because
VisADConfig.makeConfig calls getDefaultScreenDevice() which throws
a java.awt.HeadlessException.
I'm thinking that:
   (a) if I'm creating an offscreen DisplayImplJ3D, it should not be
asking for a default screen device.
or (b) DisplayImplJ3D.initialize() should gracefully handle a headless case.

Good idea. However, the VisADCanvasJ3D constructor needs a
non-null GraphicsConfiguration to pass as an argument to
the super() constructor for its parent Canvas3D class. I
took a quick look at the GraphicsConfiguration, GraphicsDevice
and GraphicsEnvironment JavaDocs but couldn't see an obvious
way to construct a GraphicsConfiguration without a GraphicsDevice.
If you or someone else can suggest a way, we can catch the
java.awt.HeadlessException in VisADCanvasJ3D.makeConfig() and
use your alternative. There is hopefully an easy way to do this
that my quick look missed.

Thanks,
Bill