Greg and all: Thank you a lot for your valuable suggestion. Now I have got the text and ColorCube shown. What I want is to periodically and alternately render a Geometry (like ColorCube) and a text. The attached herewith is the revised file PureImmediate.java. In this file, I put a loop and two conditions in run() {} to control the render of Geometry and Text. The problem is: the text can be displayed only once. There is only a blank screen shown when the text should appear afterwards. The second problem is that the disparity of the text shown is too high. I tried PhysicalBody and did not fix the problem. Could you please help me in fixing this problem?
Thank you a lot! G.B. Liu
package pureimmediata; import java.applet.Applet; import java.awt.BorderLayout; import java.awt.GraphicsConfiguration; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.GraphicsEnvironment; import java.awt.Font; public class PureImmediata extends Applet implements Runnable { int CC=0; String textShow="Testing?"; boolean renderIt=true; private Canvas3D canvas; private GraphicsContext3D gc = null; private Geometry cube = null, cube1=null; //private ColorCube cube = null, cube1=null; Shape3D shape = new Shape3D(); private Transform3D cmt = new Transform3D(); Material sphereMaterial = new Material(); Appearance sphereAppearance = new Appearance(); private Alpha rotAlpha = new Alpha(-1, 6000); private SimpleUniverse u = null; public void render() { if (gc == null) { gc = canvas.getGraphicsContext3D(); gc.setBufferOverride(true); gc.setAppearance(new Appearance()); cube = new ColorCube(0.3).getGeometry(); cube1=new ColorCube(0.2).getGeometry(); } double angle = rotAlpha.value() * 2.0*Math.PI; cmt.rotY(angle); gc.setStereoMode(GraphicsContext3D.STEREO_LEFT); gc.clear(); gc.setModelTransform(cmt); gc.draw(cube); gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT); gc.clear(); cmt.rotX(angle); cmt.rotZ(angle); gc.setModelTransform(cmt); gc.draw(cube1); canvas.swap(); } public void run() {double startTime=System.currentTimeMillis(); while (true) { if (renderIt==true) { render(); //so that canvas.swap() only when canvas runs } if (System.currentTimeMillis()-startTime>=5000) { if (canvas.isRendererRunning()==true) { canvas.stopRenderer(); renderIt=true; canvas.requestFocus(); } else if (canvas.isRendererRunning()==false) { canvas.startRenderer(); renderIt=false; canvas.requestFocus(); this.start(); } System.out.println((CC++)+" RenderIt "+renderIt); startTime=System.currentTimeMillis(); } } } public PureImmediata() { } public void init() { setLayout(new BorderLayout()); GraphicsConfigTemplate3D g3d = new GraphicsConfigTemplate3D(); g3d.setStereo(GraphicsConfigTemplate3D.REQUIRED); GraphicsConfiguration config = GraphicsEnvironment. getLocalGraphicsEnvironment(). getDefaultScreenDevice(). getBestConfiguration(g3d); canvas = new Canvas3D(config); canvas.setStereoEnable(true); canvas.stopRenderer(); add("Center", canvas); Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion()); Text3D txt = new Text3D(f3d, textShow, new Point3f(-2.0f, 0.0f, -10.0f)); Appearance app=new Appearance(); Material mat=new Material(); mat.setAmbientColor(1.0f, 1.0f, 0.2f); app.setMaterial(mat); shape.setAppearance(app); shape.addGeometry(txt); shape.setCapability( Shape3D.ALLOW_GEOMETRY_READ ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); AmbientLight ambLight=new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f)); ambLight.setInfluencingBounds(bounds); // PhysicalBody body = new PhysicalBody(); // PhysicalEnvironment environment = new PhysicalEnvironment(); // body.setLeftEyePosition(new Point3d(-0.0, -0.0, -0.0)); // body.setRightEyePosition(new Point3d(0.0, 0.0, 0.0)); // canvas.getView().setPhysicalEnvironment(environment); // canvas.getView().setPhysicalBody(body); u = new SimpleUniverse(canvas); BranchGroup group=new BranchGroup(); group.addChild(shape); group.addChild(ambLight); u.addBranchGraph(group); u.getViewingPlatform().setNominalViewingTransform(); new Thread(this).start(); } public void destroy() { u.cleanup(); } public static void main(String[] args) { new MainFrame(new PureImmediata(), 750, 400); } }