JME3 in a Swing Context

Theres a demo for it in the jme3 test classes and jMP does it as well so its definitely working :slight_smile:



Cheers,

Normen

I can't seem to find that test in the current jme3 tests:




grep -r "Swing" .
./.svn/text-base/TestChooser.java.svn-base:import javax.swing.SwingUtilities;
./.svn/text-base/TestChooser.java.svn-base:        SwingUtilities.invokeLater(new Runnable(){
./awt/.svn/text-base/AppHarness.java.svn-base:import javax.swing.SwingUtilities;
./awt/.svn/text-base/AppHarness.java.svn-base:        SwingUtilities.invokeLater(new Runnable(){
./awt/.svn/text-base/TestApplet.java.svn-base:import javax.swing.SwingUtilities;
./awt/.svn/text-base/TestApplet.java.svn-base:        SwingUtilities.invokeLater(new Runnable(){
./awt/.svn/text-base/TestCanvas.java.svn-base:import javax.swing.SwingUtilities;
./awt/.svn/text-base/TestCanvas.java.svn-base:        SwingUtilities.invokeLater(new Runnable(){
./awt/AppHarness.java:import javax.swing.SwingUtilities;
./awt/AppHarness.java:        SwingUtilities.invokeLater(new Runnable(){
./awt/TestApplet.java:import javax.swing.SwingUtilities;
./awt/TestApplet.java:        SwingUtilities.invokeLater(new Runnable(){
./awt/TestCanvas.java:import javax.swing.SwingUtilities;
./awt/TestCanvas.java:        SwingUtilities.invokeLater(new Runnable(){
./post/.svn/text-base/TestRenderToMemory.java.svn-base:import javax.swing.SwingUtilities;
./post/.svn/text-base/TestRenderToMemory.java.svn-base: * the contents to a Swing JFrame. Note that some parts are done inefficently,
./post/.svn/text-base/TestRenderToMemory.java.svn-base:        SwingUtilities.invokeLater(new Runnable(){
./post/.svn/text-base/TestRenderToMemory.java.svn-base://        SwingUtilities.invokeLater(new Runnable() {
./post/TestRenderToMemory.java:import javax.swing.SwingUtilities;
./post/TestRenderToMemory.java: * the contents to a Swing JFrame. Note that some parts are done inefficently,
./post/TestRenderToMemory.java:        SwingUtilities.invokeLater(new Runnable(){
./post/TestRenderToMemory.java://        SwingUtilities.invokeLater(new Runnable() {
./TestChooser.java:import javax.swing.SwingUtilities;
./TestChooser.java:        SwingUtilities.invokeLater(new Runnable(){



Am I missing something?

Try jme3test.awt.TestCanvas :wink: Its a Canvas, so not Swing per se but it should work. TestRenderToMemory is also very interesting if you really depend on lightweight components.

Cheers,

Normen

Hey,



Thanks for the info, but I'm getting an exception when trying to run the canvas test on a freshly ant jar'd version of the latest SVN.  Does anybody have any intuition?  Thanks for all of the help so far!



$ java -jar jMonkeyEngine3.jar
Aug 2, 2010 5:02:39 PM jme3test.TestChooser start
INFO: Composing Test list...
Aug 2, 2010 5:02:39 PM jme3test.TestChooser find
INFO: Searching for Demo classes in "jar:file:/Users/rmnoon/work_code/poincare/lib/jme3/jMonkeyEngine3.jar!/jme3test".
Aug 2, 2010 5:02:44 PM com.jme3.asset.DesktopAssetManager <init>
INFO: DesktopAssetManager created.
Aug 2, 2010 5:02:44 PM com.jme3.system.JmeSystem initialize
INFO: Running on jMonkey Engine 3 Alpha 0.6
Aug 2, 2010 5:02:44 PM com.jme3.system.lwjgl.LwjglCanvas$1 addNotify
INFO: EDT: Creating OGL thread.
Exception in thread "LWJGL Renderer Thread" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
   at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1792)
   at java.lang.Runtime.loadLibrary0(Runtime.java:823)
   at java.lang.System.loadLibrary(System.java:1045)
   at org.lwjgl.Sys$1.run(Sys.java:72)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.lwjgl.Sys.doLoadLibrary(Sys.java:65)
   at org.lwjgl.Sys.loadLibrary(Sys.java:81)
   at org.lwjgl.Sys.<clinit>(Sys.java:98)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:146)
   at java.lang.Thread.run(Thread.java:637)
Aug 2, 2010 5:02:56 PM com.jme3.system.lwjgl.LwjglCanvas$1 removeNotify
INFO: EDT: Sending re-init request..
^C



bump?  Might this be an error with the tests?

rmnoon said:

bump?  Might this be an error with the tests?

I don't think so. It's more likely how you've set up your build path. If you're using Eclipse, you need to tell it where there LWJGL jar is, so it can add it to the build path.

It's just me running the precompiled jar from the console with a standard OS X installation of Java 6.  I'm not building anything and the other tests mostly work fine.  Is there anyone with Snow Leopard who can affirm that they can run this test?

it runs fine in eclipse on snow leopard here…

does the jmonkeyeninge3.jar contain the neccessary libs and native dependencies?

I just tried incorporating the ideas from the test into my existing code and it worked!  It must've been some missing dependency not rolled into the jar or something when trying to run the test from the command line.  Thanks all!

Hi everyone.

I got error, tried to execute TestRenderToMemory on MaxOSX snow leopard, eclipse3.6, java1.6 and latest repository revision.



Do you have any idea ?



Thanks.



org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
   at org.lwjgl.opengl.Util.checkGLError(Util.java:56)
   at org.lwjgl.opengl.GL11.glDrawBuffer(GL11.java:1171)
   at com.jme3.renderer.lwjgl.LwjglRenderer.setFrameBuffer(LwjglRenderer.java:1118)
   at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:532)
   at com.jme3.renderer.RenderManager.render(RenderManager.java:564)
   at com.jme3.app.SimpleApplication.update(SimpleApplication.java:189)
   at com.jme3.system.lwjgl.LwjglOffscreenBuffer.runLoop(LwjglOffscreenBuffer.java:116)
   at com.jme3.system.lwjgl.LwjglOffscreenBuffer.run(LwjglOffscreenBuffer.java:131)
   at java.lang.Thread.run(Thread.java:637)



soh said:

Hi everyone.
I got error, tried to execute TestRenderToMemory on MaxOSX snow leopard, eclipse3.6, java1.6 and latest repository revision.

Do you have any idea ?

Thanks.

Update from SVN and try again :)

It runs fine ! Thank you !  :slight_smile:

Is there any way to get LWJGL to give me a JPanel instead of an awt canvas?  I know there's an inherent performance penalty to drawing inside of a JPanel, but mixing heavyweight and lightweight components is really really awful.  I'm trying to make a desktop app here and the overall kludginess of the awt canvas is making my life terrible.

rmnoon said:

Is there any way to get LWJGL to give me a JPanel instead of an awt canvas?  I know there's an inherent performance penalty to drawing inside of a JPanel, but mixing heavyweight and lightweight components is really really awful.  I'm trying to make a desktop app here and the overall kludginess of the awt canvas is making my life terrible.

Theres lots of info on how to mix heavyweight (awt canvas) and lightweight (swing) components properly on the net. If you really need to get rid of the heavyweight component, look at the TestRenderToMemory example and use that as a basis to get the render content into a swing window, that would be the way to do it.
Cheers,
Normen

Thanks! I'll look into that.

For now I've found a way to make the heavyweight canvas play nice with the rest of the UI so I'm holding off on the JPanel drawing but I might try it in the future.



This brings me to my next question.  I noticed that (like was said) jMonkeyPlatform uses JME3's rendered AWT canvases as viewers all over the app.  Sometimes there are multiple instances open in different views of the scene.  How is this accomplished?  I read somewhere that LWJGL uses static content in memory that makes it tough to open multiple instances (and in fact every time I've tried to open multiple JME contexts/canvases I've gotten some weird NPE).



Is there some trick to it that I'm missing that I should know before I go madly digging through the jMP source?



Thanks in advance…this community seriously rocks.

jMP uses only one openGL window but in theory jme3 supports multiple render views, I dont know about the canvas, though.

LWJGL doesn't support multiple canvases though, not with the particular method that is used in jME3.

Ok I am also rendering inside Canvas and JFrame.

I get some error (but not always, which is very strange to me). First time I run application it usually runs fine. Second time and next times I run it, I get this:


INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, OpenGL20, OpenGL21, ARBprogram, GLSL100, GLSL110, GLSL120, GLSL130, VertexTextureFetch, TextureArray, TextureBuffer, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, TextureCompressionLATC, MeshInstancing, VertexBufferArray]
Exception in thread "LWJGL Renderer Thread" java.lang.NullPointerException
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)
   at java.lang.Thread.run(Unknown Source)


This is not always true again, because sometimes it just works on some random run...
I am using Eclipse. Any ideas?  :?

Are you calling start() on the app twice?