Embedded StandardGame in Swing UI?

Hello,



Is it possible to use StandardGame inside a Swing UI?  (not a Swing UI inside StandardGame).



I tried subclassing StandardGame and overriding the initSystem method, but it seems it is not possible to just replace the display.createWindow call with a display.createCanvas call (the way the rendering is done seems different).  Is there some other better solution? 



In the worst case I can always do without StandardGame, but it would be neat to have access to all that existing thread support and such (I’m working on a 3D view for a geography library: http://docs.codehaus.org/display/GEOTOOLS/3D+Rendering+Pipeline+for+GeoTools )


Hmmm…I'll try to add that as an optional switch tonight.  However, if another developer has time before then feel free. :wink:



BTW, I've actually got quite a bit of experience with GeoTools…it was cool what you could do with the API, but I found it quite annoying to try to code with.  Hope it has gotten a lot better. :wink:

That’s right, createCanvas does not assign the GLcontext and does not create a renderer like the createWindow method does. I’ve exposed both of those problems in my issue thread.  (The StandardGame limitation and createCanvas bug)

zzorn said:


Is it possible to use StandardGame inside a Swing UI?  (not a Swing UI inside StandardGame).

I tried subclassing StandardGame and overriding the initSystem method, but it seems it is not possible to just replace the display.createWindow call with a display.createCanvas call (the way the rendering is done seems different).  Is there some other better solution? 



Hi , I've tried the exact same thing myself with no success
I've looked for a solution in the forum but I didn't find any.
so , Is it possible?
MoleHillRocker said:

Hello,
we integrated the renderwindow into our swing-app by extending the com.jmex.awt.JMECanvasImplementor class, according to the jmetest.util.JMESwingTest. Maybe this can help you.

thanks for the fast reply :)
this is not my problem though , I want to use both the standardGame and a Swing app so I could use the gameStates
this is why I ask that.

I don't see how extending the JMECanvasImplementor could help me  , or i'm missing somthing here .
I'll look into it anyway
thanks :)
moshe

You could create a GameStateManager instance yourself and update it in your loop. That way you can use GameStates without StandardGame.

Momoko_Fan said:

You could create a GameStateManager instance yourself and update it in your loop. That way you can use GameStates without StandardGame.

I'll look intoIt
thanks
moshe

I seem to have overlooked fixing this. :o



I just checked in this fix and now if you want to draw to a Canvas you need to call:


StandardGame.DISPLAY_MODE = StandardGame.DISPLAY_CANVAS;



before you invoke game.start(). After game.start() is called you can invoke:

game.getCanvas();



to return the created java.awt.Canvas that the display will be drawn on.
darkfrog said:

I seem to have overlooked fixing this. :o

I just checked in this fix and now if you want to draw to a Canvas you need to call:

StandardGame.DISPLAY_MODE = StandardGame.DISPLAY_CANVAS;



before you invoke game.start(). After game.start() is called you can invoke:

game.getCanvas();



to return the created java.awt.Canvas that the display will be drawn on.

I see darkFrog , thanks a lot man , this fix is much simpler :)
moshe

The StandardGame doesn't include the field DISPLAY_MODE and the method getCanvas(), did you update them recently?

It's ok, I saw them right now. Thanks!

Perfect timing, I'm currently moving my project from Eclipse RCP with SWT to Netbeans Platform with Swing :slight_smile:

Thanks !

Didn't realize how popular such a feature would be…would have implemented it a long time ago. :o

darkfrog said:

I seem to have overlooked fixing this. :o

I just checked in this fix and now if you want to draw to a Canvas you need to call:

StandardGame.DISPLAY_MODE = StandardGame.DISPLAY_CANVAS;



before you invoke game.start(). After game.start() is called you can invoke:

game.getCanvas();



to return the created java.awt.Canvas that the display will be drawn on.

Hello darFrog , its seems that the problem still remains
I've tried to use the StandardGame.DISPLAY_MODE = StandardGame.DISPLAY_CANVAS before game.start and getCanvas after it , but I get a null error the minute game.start() is invoked.
it is the same problem , when you call in the code
camera = display.getRenderer().createCamera(display.getWidth(), display.getHeight());
display.getRenderer() returns null thus the nullPointer error
it there somthing i'm missing?
moshe

That's a good point…it looks as though in LWJGLDisplaySystem no renderer is created so getRenderer() will return null if a Canvas is in use.



Anyone that has experience with using AWT Canvas in jME know how you're supposed to get a renderer? :o

The renderer has to be created in the proper thread (Swing thread) for things to work correctly, so normally it is created by calling initForCanvas on the DisplaySystem during canvas setup.  (See SimpleCanvasImpl.doSetup())

renanse said:

The renderer has to be created in the proper thread (Swing thread) for things to work correctly, so normally it is created by calling initForCanvas on the DisplaySystem during canvas setup.  (See SimpleCanvasImpl.doSetup())

i've tried initFoeCanvas but then the GLContex.getCababilities() returns null.
but I didn't look at SimpleCanvasImpl , i'll look there
thanks
moshe

moshad, if you're running from the source, feel free to update StandardGame and submit a patch if you get this figured out.

darkfrog said:

moshad, if you're running from the source, feel free to update StandardGame and submit a patch if you get this figured out.

if i'll figure this out (when I'll have some time to work on it ... damn day job ;) ) I will post the code here coz I have some cvs problems that I dont have time to fix :(
anyhow I just want to  say that you ppl are really great , the support here is awesome :)
moshe

Hi y'all

just wanted to update you that I've tried a couple of things to fix this with no success.

I did what renanse said and and created the render from a swing frame (using the simpleCanvasimplementor)

but the problem switched to other places and I didn't manage to get the screen to display the scene (GL context null pointer).

eventually I tried what Momoko_Fan  suggested , I created the GameStateManager instance  inside the implementor simpleSetup method

updated it in simpleUpdate and render it in simpleRender , this way after I create my canvas inside the frame and set it's implementor I have a gameStateInstance up and running , I attached some objects using debugGameState and they rendered to the scene so it seems to be working at list for the display (the mouse keyboard seems to do some troubles but I didn't work in it yet).

so if anyone wants to use the GameStates  and a swing frame , it seems that this way can work.

thanks for all your help guys

Moshe