Title: RE: [JAVA3D] Help Please
Dear Xuedong, Greg, Isaac and all:
 
Thank you for your valuable suggestions.  I tried all your suggestions and other possibilities I can imagine, the text still did not show.  I have attached the revised PureImmediate.java here for your reference.  I need to point out or ask some questions here:
 
1. Xue Dong suggested trying to change scale and take out spaces between words, I did it but no improvement found.
2. Greg suggested that In between the section where I call canvas.draw(cube/cube2) put the line canvas.swap().  I did it but still no improvement. 
3. Isaac suggested to try AmbientLight and Directional Light, I did it and still not lick. 
 
Please help me.  Thank you a lot!
 
G.B. Liu

    Hi Friends:
     
    I have been struggling with this problem for more than one week without any luck.  I have to seek your kind help! 
    Attached is an example file using Immediate mode.  What I want is to add a text on the screen.  But no matter what I did, I could never see the text.  With the same method of displaying text, I was successful in other mode.  Could any one please give me a hand about: 

    1.  How I can display an text in immediate mode?
    or
    2.  Is there any other method of display text in immediate mode? 
     
    Thank you!
     
    G.B. Liu << File: PureImmediate.java >>

package pureimmediate;

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 PureImmediate extends Applet implements Runnable {

    private Canvas3D canvas;
    private GraphicsContext3D gc = null;
    private Geometry cube = null, cube1=null;

    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);
        canvas.swap();
        gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
        gc.clear();
        cmt.rotX(angle);
        cmt.rotZ(angle);
        gc.setModelTransform(cmt);
        gc.draw(cube1);
        canvas.swap();
    }
    public void run() {
        while (true) {
            render();
            Thread.yield();
        }
    }


    public PureImmediate() {
    }
    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, 3),
                           new FontExtrusion());
   Text3D txt = new Text3D(f3d, "ClickingMe",
                new Point3f(-1.0f, 0.0f, 1.0f),
                Text3D.ALIGN_CENTER,
                Text3D.PATH_LEFT);
   Appearance app=new Appearance();
   BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
   Material mat=new Material();
    AmbientLight ambLight=new AmbientLight(new Color3f(1.0f, 0.0f, 0.0f));
    ambLight.setInfluencingBounds(bounds);
    DirectionalLight difLight=new DirectionalLight(new Color3f(0.5f, 0.0f, 0.0f),
                              new Vector3f(-1.0f, -1.0f, -1.0f));
   difLight.setInfluencingBounds(bounds);

   app.setMaterial(mat);
   Shape3D shape=new Shape3D(txt, app);
   shape.setBounds(bounds);
   shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
   app.setCapability(Appearance.ALLOW_MATERIAL_READ);
   mat.setCapability(Material.ALLOW_COMPONENT_READ);
   mat.setCapability(Material.ALLOW_COMPONENT_WRITE);
   mat.setAmbientColor(0.1f, 0.0f, 0.5f);
   mat.setDiffuseColor(0.0f, 1.0f, 0.0f);
   u = new SimpleUniverse(canvas);
   BranchGroup group=new BranchGroup();
   group.addChild(shape);
   group.addChild(ambLight);
   group.addChild(difLight);
   u.addBranchGraph(group);
   u.getViewingPlatform().setNominalViewingTransform();
   new Thread(this).start();
    }

    public void destroy() {
        u.cleanup();
    }

    public static void main(String[] args) {
        new MainFrame(new PureImmediate(), 800, 550);
    }
}

Reply via email to