Software rendering and swing components

Started by ErDetEnAnd?, August 28, 2008, 10:26:26 AM

Previous topic - Next topic

ErDetEnAnd?

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.

EgonOlsen

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.

raft

the trick is doing the rendering in awt/swing thread. see this post 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

JavaMan

You could also get jpct to render into a Graphics context like from a jpanel.

ErDetEnAnd?

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!

raft

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.

ErDetEnAnd?

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.

raft

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


ErDetEnAnd?

Exactly, the rendering is done when updating the frame buffer.