how to blit jcomponents?

Started by robby, December 11, 2004, 07:37:08 PM

Previous topic - Next topic

robby

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?

EgonOlsen

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:

raft

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

r a f t

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.
Regards,
Andrei

raft

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 ?

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.

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

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

raft

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
r a f t
i'm afraid Egon will kick our asses as this is not a swing-awt forum :roll:

EgonOlsen

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:

raft

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:
r a f t

entis

#9
Quote from: raft 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

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.

raft

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

entis

Quote from: raft 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

My canvas is JPanel...

raft

mm strange. where do you call frameBuffer.display(canvas.getGraphics()) ? in which method and in which thread ?

entis

#13
Quote from: raft 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 ?

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.

raft

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