Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Add a Canvas3D to the JPanel  (Read 5781 times)
0 Members and 1 Guest are viewing this topic.
Offline tsjung75

Junior Newbie

Java games rock!

« Posted 2003-10-29 09:48:23 »


I started to convert my Java3D code to Xith3D code.
But I couldn't add a Canvas3D object to the JPanel.
Here is a code fragment.

// create a canvas for our graphics
RenderPeer rp = new RenderPeerImpl();
CanvasPeer cp = rp.makeCanvas(panel, 384 + 54, 384 + 54, 32, offScreen);
Canvas3D canvas3d = new Canvas3D();

Is this feature not yet implemented?
Please give me a advice...
Offline Yuri Vl. Gushchin

Senior Devvie

Speak Java!

« Reply #1 - Posted 2003-10-29 13:30:03 »

This feature is implemented and working, I am using this in some of my applications.

Can you please make a short example of what is not working for you and post it here, because the code above looks OK for a first look.


Yuri Vl. Gushchin
JProof Group
Offline tsjung75

Junior Newbie

Java games rock!

« Reply #2 - Posted 2003-10-29 23:41:49 »

Hi, Here is modified HelloXith3D version.

           JFrame frame = new JFrame();
           frame.setBounds(100, 100, 500, 400);
           JButton click = new JButton("Click");
           frame.getContentPane().add(click, BorderLayout.NORTH);
           JPanel panel = new JPanel();

-->            frame.setVisible(true);

           // create the virtual univers
           VirtualUniverse universe = new VirtualUniverse();

           // add a view to the universe
           View view = new View();

           // add a locale
           Locale locale = new Locale(5.0f, 0.0f, 10.0f);

           // create a BranchGroup
           BranchGroup scene = new BranchGroup();

           // let objects along this path rotate
           Transform3D rotate = new Transform3D();
           TransformGroup objRotate = new TransformGroup(rotate);

           // create Cube
           Geometry geo = Cube.createCubeViaTriangles(0, 0, 0, 1, true);
           Shape3D sh = new Shape3D(geo, new Appearance());

           // turn the scene into a render friendly format

           // create a canvas for our graphics
           RenderPeer rp = new RenderPeerImpl();
           CanvasPeer cp = rp.makeCanvas(panel, 500, 380, 32, false);
           Canvas3D canvas = new Canvas3D();

           // modify our view so we can see the cube
                 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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Yuri Vl. Gushchin

Senior Devvie

Speak Java!

« Reply #3 - Posted 2003-10-30 06:35:29 »

I can comment only on possible reason for "invalid drawable" error.

View.startView() call starts separate rendering thread for the view, which is for now is nothing than

{ renderOnce(); }

renderOnce() immediately calling the painting operation of JOGL GLCanvas, and if it is not visible (because of its parent invisible), there may be some problems allocating system resources for OpenGL context, which may cause such errors.

Anyway, I see no reason why you should have your view started before it will become visible - user will not see rendering results anyway.


Yuri Vl. Gushchin
JProof Group
Offline tsjung75

Junior Newbie

Java games rock!

« Reply #4 - Posted 2003-10-30 08:21:26 »

Thanks for your reply.

I need to start a view even though that is not visible.
For example, Let's say I use a JTabbedPane and add three tabs.
The last one contains Canvas3D that is connected to view.
So at first, the third tab is not seen.
I want to start a view at the construct time of the third tab and
forget about it.
In this case, how can I accomplish this?

Offline Yuri Vl. Gushchin

Senior Devvie

Speak Java!

« Reply #5 - Posted 2003-10-30 12:43:02 »

In current implementation of Xith3D you have to take care about these things (I mean visibility of canvas, minimization, etc.).

For me, the easiest way to do this is to provide your own implementation of rendering thread that will take care of all the things important for you.

As far as the implementation of Xith3D rendering thread does not take into account canvas visibility status and scene changes, it will produce unnecessary CPU load if canvas is not visible. So, I will recommend to put some efforts in this and make sure you are doing rendering only when user can see it.

Xith3D provides all the functionality you need to implement your own rendering thread.

BTW, this is up to you and I only describe how Xith3D works for now (maybe this will change in future a bit).


Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Devvie

Medals: 4

« Reply #6 - Posted 2003-11-05 06:04:05 »

Hi. I've got a similar problem. I'm about to move my Jogl application to Xith3d. I use a Frame which holds a GLCanvas next to some more AWT/Swing components.

Now I'd like to replace the GLCanvas with a Canvas3D component.

While the following works it takes about 5 secs until the Xith3d's canvas3d appears inside the Frame:
// A Frame called mFrame does alread exist (visible).
// It holds a Canvas3D object named mCanvas3d

RenderPeer rp = new RenderPeerImpl();
CanvasPeer cp = rp.makeCanvas(mFrame, 320, 200, 32, false);

Does this mean my Canvas3D holds the GLCanvas which is internally created by Xith3d?
How could I avoid this? Or rather: what's the official way to embed an Xith3d Canvas3D inside a Frame (or JFrame) ?

Offline Yuri Vl. Gushchin

Senior Devvie

Speak Java!

« Reply #7 - Posted 2003-11-05 06:32:19 »

Canvas3D holds a reference to instance of CanvasPeer. CanvasPeer is renderer-specific class that holds Component which represents actual rendering surface (in case of JOGL rendering peer it is GLCanvas). Call to RenderPeerImpl.makeCanvas(...) with non-null owner automatically adds rendering surface [read: GLCanvas] to the owner.

Currently, this is the official way of how to add rendering surface to your frame.

You never deal directly with GLCanvas, but you can obtain reference to it using canvas3d.get3DPeer().getComponent(). If you will use another renderer, this may be object other than GLCanvas. Xith3D specs only say it will be instance of Component.


Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Devvie

Medals: 4

« Reply #8 - Posted 2003-11-05 06:56:49 »


How could I get the x- and y- dimension of the empty Canvas3D which is being created in the mFrame before I call renderpeer.makeCanvas(...) ?

I thought mCanvas.getWidht() and getHeight() however they provide a null pointer exception. (Probably because the Canvas3D doesn't hold a GLCanvas yet.)

Is this a "chicken - egg" problem? :)
Offline Preston

Senior Devvie

Medals: 4

« Reply #9 - Posted 2003-11-05 11:11:10 »

I'm wondering why the following code "sleeps" about five secs when makeCanvas() is being called. Five secs on a fast PC. :-)
Frame frame = new Frame();
Canvas3D canvas = new Canvas3D();
frame.add(canvas, BorderLayout.CENTER);
frame.add(anothercomponent, BorderLayout.SOUTH);
frame.setSize(640, 480);

RenderPeer rp = new RenderPeerImpl();
CanvasPeer cp = rp.makeCanvas(frame, 320, 200, 32, false);

Two notes:
a) When I give null to makeCanvas(..) instead of the "frame", Xith3d starts immediately. But I've got two windows then, so not my desired effect. :-)

b) When I move the "frame.setVisible()" call to the end of the code {after canvas.set3DPeer(..)} the whole thing works immediately.

I thought the frame containing the Canvas3D had to be visible from the beginning (see original poster) but ... apparently it's enough that the Canvas3D is inserted into the frame via frame.add(..)

Strange, but it works fine now.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (13 views)
2015-07-29 04:35:27

Riven (36 views)
2015-07-27 16:38:00

Riven (18 views)
2015-07-27 15:35:20

Riven (21 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (30 views)
2015-07-25 00:14:37

BurntPizza (41 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (27 views)
2015-07-22 22:16:53

NoxInc (18 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!