|
Hi, Here is modified HelloXith3D version.
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(100, 100, 500, 400); JButton click = new JButton("Click"); frame.getContentPane().add(click, BorderLayout.NORTH); JPanel panel = new JPanel(); frame.getContentPane().add(panel);
--> frame.setVisible(true);
// create the virtual univers VirtualUniverse universe = new VirtualUniverse();
// add a view to the universe View view = new View(); universe.addView(view);
// add a locale Locale locale = new Locale(5.0f, 0.0f, 10.0f); universe.addLocale(locale);
// create a BranchGroup BranchGroup scene = new BranchGroup(); locale.addBranchGraph(scene);
// let objects along this path rotate Transform3D rotate = new Transform3D(); rotate.rotXYZ((float)Math.PI/4, (float)Math.PI/5, (float)Math.PI/2); TransformGroup objRotate = new TransformGroup(rotate); scene.addChild(objRotate);
// create Cube Geometry geo = Cube.createCubeViaTriangles(0, 0, 0, 1, true); Shape3D sh = new Shape3D(geo, new Appearance()); objRotate.addChild(sh);
// turn the scene into a render friendly format scene.compile();
// create a canvas for our graphics RenderPeer rp = new RenderPeerImpl(); CanvasPeer cp = rp.makeCanvas(panel, 500, 380, 32, false); Canvas3D canvas = new Canvas3D(); canvas.set3DPeer(cp);
// modify our view so we can see the cube view.addCanvas3D(canvas); view.getTransform().lookAt( new Vector3f(0, 0, 2f), // location of eye new Vector3f( 0, 0, 0), // center of view new Vector3f( 0, 1, 0)); // vector pointing up --> view.startView();
There is a problem. When I call frame.setVisible(true) before view.startView(). It works. But When I change the order, I always see the "invalid drawable". error message.
I tested this code on MacOS X Panther(7B95) with September 5th build.
Is this only a problem related with MacOS JOGL implementation? Which situation can I see "invalid drawable" message?
P.S) My program(other one) use IndexedTriangleStripArray and GeometryUpdater for dynamic geometry update. When I port Java3D code to Xith3D code, Could you tell me about pitfalls that I must care?
And I use a JTabbedPane in which Canvas3D is attached. But there is painting problem.
|