Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Placing a Swing JComponent inside an LWJGL Display  (Read 11114 times)
0 Members and 1 Guest are viewing this topic.
Offline J0
« Posted 2015-10-18 14:28:19 »

*thinks to himself* okay J0, this is the last time you begin a new thread in Newbie questions

Hi lads! And good afternoon! Cheesy

First a little background; I'm currently coding a game that will have an RPG part and a Puzzle part (and a few other surprises but I leave that to the featured page in which I will post about that game once I'm finished). I don't know if this would help, but maybe you can think of it as a Pr Layton game, in which you were able to move around in town, and solve puzzles. It's not exactly the same type of game, but you get my point.

Anyway, I already coded some time ago my Puzzle part, using Swing, which was the only graphical library I knew at that time. I more recently began coding the RPG part, but, since Swing was too weak to make that work, I switched to using LWJGL, based on the advice of some people around here Smiley

So we can now say I have an LWJGL Display in which the RPG (as well as every other) part shows up pretty smoothly and looking nice to me. On the other side, I have my Puzzle JComponent, all alone in its Swing shell. Yup, that's right, like a tiny, shy turtle. Roll Eyes
Hence my question: how can I make my JComponent appear inside my Display? persecutioncomplex The Display is full screen and the JComponent was made adaptable so it should acclimate to a full screen state very easily, if that is of any help.

I searched a lot on the internet before coming here to ask how to do it, unfortunately it appears that a lot of people ask about trying to make LWJGL fit inside Swing, and not the opposite. Which is why I came to think that doing what I want to do is either completely dumb, or super easy to achieve. Cool

THANKS A LOT FOR ANY ANSWER Grin (woops capslock)

J0 Smiley

Offline KaiHH

JGO Kernel


Medals: 787



« Reply #1 - Posted 2015-10-18 14:41:29 »

Even though you sound like you ruled that option out I would still recommend you use LWJGL2's AWTGLCanvas class to embed OpenGL into a Swing application, instead of using LWJGL2's native Display.
With this you can show up that AWTGLCanvas whenever you are in your RPG world and simply show up your other JComponent whenever solving puzzles.
There is also the option to set a AWT Canvas as the Display's parent, using Display.setParent().
This way the OpenGL context is created on the window handle of the supplied AWT Canvas, which you can also add to your JFrame, just like your Puzzle JComponent.
Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #2 - Posted 2015-10-18 15:46:15 »

if you want to show a JComponent _next_ to your gl-display, use what KaiHH said : make the gl-display a JComponent.

there is another nice advantage by using an AWT Canvas. it becomes a plain JComponent which means you can make your game run in "windowed-fullscreen" very easy :

you can remove the frame from the JFrame
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE)
.


to make the frame overlap the taskbar you can modify the maximum bounds :
frame.setMaximizedBounds( new Rectangle(0,0,  width, height ) )
with
width
and
height
match the desktop resolution :

DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode()
holds those numbers.

if you want to show a JComponent _over_ your gl-display, like any other gl-drawn element you can go down the rabbit hole and look into swing->gl look and feel implementations but that's rather heavy and probably way more work than .. just rewriting the old JComponent in pure GL.

o/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline J0
« Reply #3 - Posted 2015-10-18 16:08:04 »

Thanks for your quick answers, @KaiHH and @basil_! Grin

embed OpenGL into a Swing application, instead of using LWJGL2's native Display.
That is exactly what I feared I would have to do Cheesy
(No particular reason for that, I just had a feeling I would, in the end, have to embed OpenGL into a JFrame, haha)

Well then, I'm off to coding that, after what I'll have to have a look at how I want my battles made Wink

Farewell!

J0 Smiley

Offline J0
« Reply #4 - Posted 2015-10-18 16:52:19 »

Problem solved! Cheesy
Well, the GL Display is maybe a little slower when it has an AWT Canvas as parent, but that is not a big deal Wink As long as it runs smoothly! Tongue

Thanks again!

J0

Offline philfrei
« Reply #5 - Posted 2015-10-18 19:39:55 »

Sounds like an answer has already been found and is satisfying to the OP.

But I am wondering, would another possible answer be to use JavaFX? Converting a Swing component to a JavaFX correlate is usually very easy. And JavaFX implements many (what percentage?) of the elements of LWJGL, e.g., things like shaders, 3D, etc. I don't know how difficult it would be to convert existing code using LWJGL to JavaFX.

Lastly, I don't know if there would be a performance hit or not. But at least the components and RPG elements should play together nicely. How is this as a theoretical solution? I'm just wondering about JavaFX as an option.

music and music apps: http://adonax.com
Offline princec

« JGO Spiffy Duke »


Medals: 1136
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2015-10-18 21:02:01 »

Short answer: JavaFX and OpenGL bindings don't currently play very efficiently together. It's a crying shame.

Cas Smiley

Offline gouessej
« Reply #7 - Posted 2015-10-18 21:46:00 »

And JavaFX implements many (what percentage?) of the elements of LWJGL, e.g., things like shaders, 3D, etc. I don't know how difficult it would be to convert existing code using LWJGL to JavaFX.
The JavaFX 3D Graphics API is closer to Java3D than any set of Java binding for the OpenGL/OpenGL ES API, I wouldn't compare them, they don't have the same role. A scenegraph API usually uses another API to access OpenGL instead of reinventing the wheel.

Short answer: JavaFX and OpenGL bindings don't currently play very efficiently together. It's a crying shame.
Which bindings? Spasi already posted an interesting demo, a contributor has spent a lot of time in implementing an hardware accelerated pipeline for OpenJFX/JavaFX based on JOGL 2 and the main maintainer of a scenegraph API based on JOGL showed us a smart example of interoperability between JOGL and OpenJFX/JavaFX. It will become more straightforward when Oracle releases an equivalent of JAWT for OpenJFX/JavaFX.

Julien Gouesse | Personal blog | Website | Jogamp
Offline Spasi
« Reply #8 - Posted 2015-10-24 19:12:53 »

a contributor has spent a lot of time in implementing an hardware accelerated pipeline for OpenJFX/JavaFX based on JOGL 2

We moved to a new home and will be without internet for a week or two. So, I got bored and decided to try this approach:



The JavaFX Ensemble application running on top of LWJGL without any custom native code.
Offline gouessej
« Reply #9 - Posted 2015-10-25 00:04:17 »

The JavaFX Ensemble application running on top of LWJGL without any custom native code.
Good job, I'm impatient to see your source code.

Julien Gouesse | Personal blog | Website | Jogamp
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (438 views)
2019-09-04 15:33:17

hadezbladez (5292 views)
2018-11-16 13:46:03

hadezbladez (2212 views)
2018-11-16 13:41:33

hadezbladez (5561 views)
2018-11-16 13:35:35

hadezbladez (1156 views)
2018-11-16 13:32:03

EgonOlsen (4592 views)
2018-06-10 19:43:48

EgonOlsen (5467 views)
2018-06-10 19:43:44

EgonOlsen (3127 views)
2018-06-10 19:43:20

DesertCoockie (4023 views)
2018-05-13 18:23:11

nelsongames (4739 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!