www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: ErDetEnAnd? on August 28, 2008, 10:26:26 am

Title: Software rendering and swing components
Post by: ErDetEnAnd? on August 28, 2008, 10:26:26 am
Hi.

By using the software render, how is it possible to add swing components on the same pane you're drawing the world on. The swing components should be on top of the rendered scene. Is there a right way to do this?

Regards.
Title: Re: Software rendering and swing components
Post by: EgonOlsen on August 28, 2008, 02:44:46 pm
I can't answer that. I don't know much about Swing and GUI stuff. But it is doable, raft did that in karga for example.
Title: Re: Software rendering and swing components
Post by: raft on August 29, 2008, 02:54:30 am
the trick is doing the rendering in awt/swing thread. see this post (http://www.jpct.net/forum2/index.php/topic,1032.msg6421.html#msg6421) for a discussion. there is also a working example there

for layout and arrangement of components, i use a JLayeredPane. at the bottom is my jpctPanel which does the rendering and on top of them are the other swing components

r a f t
Title: Re: Software rendering and swing components
Post by: JavaMan on August 29, 2008, 04:13:36 pm
You could also get jpct to render into a Graphics context like from a jpanel.
Title: Re: Software rendering and swing components
Post by: ErDetEnAnd? on September 01, 2008, 01:10:05 pm
Thank you for your replies. This makes this engine even more advantageous to use.

The problem using the event queue is, that the runnable object is called after all pending events are processed, and this is causing flicker.

The solution I found is using the existing jpct buffered image, and by creating a new graphic object from the buffer, swing components can be drawn before displaying the contents. This lets me have swing components on the same pane as the rendered scene, but like it was a normal jpanel.

Best regards!
Title: Re: Software rendering and swing components
Post by: raft on September 01, 2008, 01:24:35 pm
if you mean SwingUtilities.invokeAndWait(Runnable) thing, that shouldnt cause a flicker. as far as i remember all swing components are double buffered by default. albeit it is true runnable is exucuted after all pending events are processed. maybe there was something else ?

the sample i provided also lets you using rendering panel like any other JPanel.
Title: Re: Software rendering and swing components
Post by: ErDetEnAnd? on September 01, 2008, 04:21:05 pm
As far as I can see the sample you referred to does not mix swing components on the jpct frame (image a JButton right in the middle of your scene). I did something like that sample before (as a temp. solution), and it worked fine without using the swing utilities. Maybe because I dont have a busy thread.

Swing components are double buffered as default, but we cant benefit from this here; we want JPCT to do its work and all components to be drawn but not shown before the last components is drawn, respectively. JPCT is using a double buffer which is updated entirely before shown. Now I'm drawing the component to that buffer, and it takes no unnecessary cpu time.
Title: Re: Software rendering and swing components
Post by: raft on September 01, 2008, 05:21:39 pm
you can disable double buffering if you wish. strange but in my tests i didnt experience any performance increase that way

that sample does not place components on top of each other, but rendering mechanism is the same as what i do in karga. (well indeed, i render to an image, then copy that image to screen in paintComponent(g) method). karga has a very complicated gui, there are lots of semi transparent panels placed on top of render panel (layouted by a JLayeredPane) and all works fine. see karga shots page (http://www.aptalkarga.com/en/album/index.html) for sample screenshots.

where exactly do you do the rendering ? if you dont use SwingUtilities it means you do not do the rendering in awt/swing thread. and  that way, if you place multiple components on top of each other you will run into problems. remember swing/awt is not thread safe

Title: Re: Software rendering and swing components
Post by: ErDetEnAnd? on September 03, 2008, 10:30:59 am
Exactly, the rendering is done when updating the frame buffer.