Author Topic: how to blit jcomponents?  (Read 13150 times)

robby

  • Guest
how to blit jcomponents?
« on: December 11, 2004, 07:37:08 pm »
Hi there,

First I've to say thanks for this great engine.

But after some tests i got a problem in programming.

I wanted to implement a console (just like in sume q**ke shooters or half-life) in my game.
So after pressing a key the sonsole should turn into the screen.
But how could i add a JTextField in my scene.

Or is there another way to show something like a textfield which can be used to accept commands in there?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
how to blit jcomponents?
« Reply #1 on: December 12, 2004, 01:45:23 pm »
Render and blit your own textfield like thingy independent from Swing...that's at least what i would do, because it will still work in OpenGL mode and it will look like the actual game, not like a Swing GUI-component on top of it. However, Swing is the most counter intuitive API there is for me, so i avoid using it like the plaque anyway...so i'm not the right person to answer this question in an unbiased manner.... :wink:

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: how to blit jcomponents?
« Reply #2 on: July 26, 2005, 12:53:39 pm »
Quote from: "robby"

But how could i add a JTextField in my scene.

i used a JLayeredPane to show such components. at the bottom layer is my graphics component and on top of that there are may others: panels, text fields etc

as Egon said, that way you are stuck to software renderer since you cant mix awt and swing components in a JLayeredPane. if you do, independent of their layer, awt component show up at the top (heavy vs light-weight stuff)

it effects the performance somehow but it works even for a quite complicated gui which is impossible or very hard to implement with blitting

Code: [Select]
r a f t

Offline rolz

  • float
  • ****
  • Posts: 280
  • Technocrat
    • View Profile
how to blit jcomponents?
« Reply #3 on: July 26, 2005, 01:32:42 pm »
technopolies uses AWT gui elements. The only sad thing about this approach is that you cannot use transparency for awt elements (thus limited only for rectangular shapes) which are displayed on top of AWTGLCanvas.
Regards,
Andrei

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
how to blit jcomponents?
« Reply #4 on: July 26, 2005, 03:48:53 pm »
Quote from: "rolz"
technopolies uses AWT gui elements. The only sad thing about this approach is that you cannot use transparency for awt elements (thus limited only for rectangular shapes) which are displayed on top of AWTGLCanvas.

so how do you layer them, in a JLayeredPane ?

Offline rolz

  • float
  • ****
  • Posts: 280
  • Technocrat
    • View Profile
how to blit jcomponents?
« Reply #5 on: July 26, 2005, 05:03:54 pm »
nope, they are not layered at all. JLayeredPane could not be used with AWTGLCanvas as it is a heavyweight component and will supress all other lightweight components on a layered pane.

Still you can place heavyweight components to a panel and set lower order for UI elements:
Code: [Select]

panel.add(glCanvas);
panel.add(leftMenu,0);
panel.add(rightMenu,0);
panel.add(centerMenu,0);
Regards,
Andrei

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
how to blit jcomponents?
« Reply #6 on: July 26, 2005, 05:37:30 pm »
Quote from: "rolz"
nope, they are not layered at all. JLayeredPane could not be used with AWTGLCanvas as it is a heavyweight component and will supress all other lightweight components on a layered pane.

not exactly. it is true that if you mix awt and swing components, awt components will show up at the top independent of their layers. but you can still use JLayeredPane and layering if all your components are awt (heavy weight) components.

i thought you were doing this, thats why i asked
Code: [Select]
r a f t
i'm afraid Egon will kick our asses as this is not a swing-awt forum :roll:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
how to blit jcomponents?
« Reply #7 on: July 26, 2005, 11:07:40 pm »
Quote from: "raft"
i'm afraid Egon will kick our asses as this is not a swing-awt forum :roll:
No no...feel free to discuss this topic here. I just can't contribute to this thread...all i'm getting when i'm using Swing are grey rectangles... :oops:

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
how to blit jcomponents?
« Reply #8 on: July 27, 2005, 03:06:09 pm »
Quote from: "EgonOlsen"
I just can't contribute to this thread...all i'm getting when i'm using Swing are grey rectangles... :oops:

who cares ? as long as you support jPCT  :wink:
Code: [Select]
r a f t

Offline entis

  • byte
  • *
  • Posts: 32
    • View Profile
Re: how to blit jcomponents?
« Reply #9 on: April 11, 2008, 12:43:01 pm »
Quote from: robby
But how could i add a JTextField in my scene.
i used a JLayeredPane to show such components. at the bottom layer is my graphics component and on top of that there are may others: panels, text fields etc

as Egon said, that way you are stuck to software renderer since you cant mix awt and swing components in a JLayeredPane. if you do, independent of their layer, awt component show up at the top (heavy vs light-weight stuff)

it effects the performance somehow but it works even for a quite complicated gui which is impossible or very hard to implement with blitting

Code: [Select]
r a f t

Hi,

I have a question about using the JLayeredPane component with jpct (in sw rendering mode)... I can't get how can I use it to prevent my swing components to be overpainted with jpct (i.e. frameBuffer.display(canvas.getGraphics()))... I add my JPanel on which I draw a scene with jpct on the bottom of JLayeredPane (i.e. layeredPane.add(canvas, new Integer(0))) then I add some other components to JLayeredPane's top (i.e. layeredPane.add(comboBox, new Integer(1)))... But still my combobox is behind the canvas... Of course everything works fine when I remove "frameBuffer.display(canvas.getGraphics())" - my components are painted in correct order...

Thanks in advance.
« Last Edit: April 11, 2008, 12:51:25 pm by entis »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: how to blit jcomponents?
« Reply #10 on: April 11, 2008, 12:50:48 pm »
if your canvas is awt.Canvas and combo is JComboBox, it's normal. you cant mix awt and swing components that way. google for "swing, mixing heavy and lightweight" etc

Offline entis

  • byte
  • *
  • Posts: 32
    • View Profile
Re: how to blit jcomponents?
« Reply #11 on: April 11, 2008, 12:52:11 pm »
if your canvas is awt.Canvas and combo is JComboBox, it's normal. you cant mix awt and swing components that way. google for "swing, mixing heavy and lightweight" etc

My canvas is JPanel...

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: how to blit jcomponents?
« Reply #12 on: April 11, 2008, 01:00:57 pm »
mm strange. where do you call frameBuffer.display(canvas.getGraphics()) ? in which method and in which thread ?

Offline entis

  • byte
  • *
  • Posts: 32
    • View Profile
Re: how to blit jcomponents?
« Reply #13 on: April 11, 2008, 01:09:40 pm »
mm strange. where do you call frameBuffer.display(canvas.getGraphics()) ? in which method and in which thread ?

I call it in a separate thread wich performs all the rendering work in my app... In a word I have main thread (where all the gui is created and its behaviour is described) and a child thread where I perform rendering which in its turn has a link to canvas (JPanel) that is created in the main thread... By the way may be it is important that it's not a standalone app but an applet.
« Last Edit: April 11, 2008, 01:11:25 pm by entis »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: how to blit jcomponents?
« Reply #14 on: April 11, 2008, 01:17:42 pm »
possibly that's the problem. you shouldn't do gui things in a thread other then awt event dispatching thread (if you want to use swing components)

try setting up a mechanism as described in this thread: it's almost the same as what i do in karga
http://www.jpct.net/forum2/index.php/topic,1032.msg6421.html#msg6421