Author Topic: Software rendering and swing components  (Read 5844 times)

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Software rendering and swing components
« 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Software rendering and swing components
« Reply #1 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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Software rendering and swing components
« Reply #2 on: August 29, 2008, 02:54:30 am »
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

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Software rendering and swing components
« Reply #3 on: August 29, 2008, 04:13:36 pm »
You could also get jpct to render into a Graphics context like from a jpanel.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Software rendering and swing components
« Reply #4 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!

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Software rendering and swing components
« Reply #5 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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Software rendering and swing components
« Reply #6 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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Software rendering and swing components
« Reply #7 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 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


Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Software rendering and swing components
« Reply #8 on: September 03, 2008, 10:30:59 am »
Exactly, the rendering is done when updating the frame buffer.