Title: Network Blitz

Hi Friends:
 
Still the same problem about rendering a text and Geometry in Immediate mode.  The attached is my file for your reference.  I want the text and geometry rendered alternately.  But after the text is shown for the first time, it is not visible. 
If I comment off the rendering of geometry (gc.draw(cube); gc.dra(cube1);), then the text can be displayed correctly.  Could you please help me diagnose about the reason about this problem?   and how to fix it?  Is it possible to render both text and Geometry at the same time?
 
Thank you a lot!
 
Guang Bin 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;
import java.awt.CardLayout;

public class PureImmediata extends Applet implements Runnable {
int CC=0;
String textShow="Testing?";
    boolean renderIt=false;
    private Canvas3D canvas, canvas1;
    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.setFrontBufferRendering(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.postRender();
               canvas.stopRenderer();
               renderIt=true;
              }
            else if (canvas.isRendererRunning()==false)
              {
           //     canvas.postSwap();
//                canvas.preRender();
               canvas.startRenderer();
               renderIt=false;
              }
 //             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);
    }
}

Reply via email to