I'm running into a chicken-and-egg problem when trying to
dynamically create Java3D images from within a servlet.
I assume that I need to set java.awt.headless=true, but if
I do so, then there seems to be no way to create a GraphicsConfiguration
object that Canvas3D will accept.

My question:
  (a) How do I create a valid GraphicsConfiguration in headless mode?
  (b) If I can not do (a), is there a way to generate java3d-rendered
images in  servlets?

Here is test code that illustrates my problem:

[EMAIL PROTECTED] test]$ cat TestOffScreen.java
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.media.j3d.*;
import java.io.*;
import java.awt.*;

public class TestOffScreen {

  public static GraphicsConfiguration withHead() throws Exception
  {
    System.out.println("GraphicsConfiguration based on screen device");
    // fails if java.awt.headless=true
    return (
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(new
GraphicsConfigTemplate3D()) );
  }

  public static GraphicsConfiguration withImage() throws Exception
  {
    System.out.println("GraphicsConfiguration based on image");
      // throws ClassCastException  at
javax.media.j3d.J3dGraphicsConfig.isValidPixelFormat(J3dGraphicsConfig.java:28)
 when Canvas3D is instantiated
      BufferedImage template = ImageIO.read( new File("/tmp/test.jpg") );
      Graphics2D g = template.createGraphics();
      GraphicsConfiguration config = g.getDeviceConfiguration();
      return config;
  }

  public static void main(String[] args) throws Exception {

      GraphicsConfiguration config = null;
      if ( args.length == 0 )
         config = withHead();
      else
         config = withImage();

      if ( config != null )
         System.out.println("Got valid graphics configuration");

      Canvas3D myCanvas = new Canvas3D( config, true );
   }
}



Can't use ScreenDevice in headless mode:


[EMAIL PROTECTED] test]$ java -Djava.awt.headless=true TestOffScreen
GraphicsConfiguration based on screen device
Exception in thread "main" java.awt.HeadlessException
        at
sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:66)
        at TestOffScreen.withHead(TestOffScreen.java:14)
        at TestOffScreen.main(TestOffScreen.java:31)




So, how do I create a valid GraphicsConfiguration object in headless mode?


[EMAIL PROTECTED] test]$ java -Djava.awt.headless=true TestOffScreen 2
GraphicsConfiguration based on image
Got valid graphics configuration
Exception in thread "main" java.lang.ClassCastException
        at
javax.media.j3d.J3dGraphicsConfig.isValidPixelFormat(J3dGraphicsConfig.java:28)
        at
javax.media.j3d.Canvas3D.compatibleGraphicsConfiguration(Canvas3D.java:837)
        at javax.media.j3d.Canvas3D.<init>(Canvas3D.java:891)
        at TestOffScreen.main(TestOffScreen.java:38)

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to