Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 4838 times)
0 Members and 1 Guest are viewing this topic.
Offline tsjung75

Junior Newbie




Java games rock!


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

Hi,

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();
canvas3d.set3DPeer(cp);

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

Senior Member




Speak Java!


« Reply #1 - Posted 2003-10-29 14: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

Yuri Vl. Gushchin
JProof Group
Offline tsjung75

Junior Newbie




Java games rock!


« Reply #2 - Posted 2003-10-30 00:41:49 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #3 - Posted 2003-10-30 07: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

while(!done)  
{ 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

Yuri Vl. Gushchin
JProof Group
Offline tsjung75

Junior Newbie




Java games rock!


« Reply #4 - Posted 2003-10-30 09: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 Member




Speak Java!


« Reply #5 - Posted 2003-10-30 13: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

Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Member


Medals: 4



« Reply #6 - Posted 2003-11-05 07: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:
1  
2  
3  
4  
5  
6  
// 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);
mCanvas3d.set3DPeer(cp);


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) ?

Thanks.
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #7 - Posted 2003-11-05 07: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

Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Member


Medals: 4



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

Thanks.

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 Member


Medals: 4



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

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

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

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (55 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!