Jump to content
  • Advertisement
Sign in to follow this  
SteveTaylor

[java] [JNI] Render to JPanel

This topic is 3410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making an editor for an Irrlicht-based game. The game itself uses Irrlicht 1.5, so it's a native C++ app. However the editor I'm making is being written using Java and Swing. The editor will contain an area to which Irrlicht will render itself. I've looked into using java.awt.Canvas on the Java side and following the directions given in the comments in jawt.h which is designed for the task. However the problem is the Canvas is heavyweight and therefore rendered on top of everything else, which includes the drop-down menus. I can't use AWT menus because I'm building the editor atop the NetBeans Platform. So I'm looking for a way to render on the native side to a lightweight component, which would probably be a JPanel. I have a feeling it's got something to do with BufferedImage and/or ByteBuffer, but since I don't know much about these things or about JNI, I'm having difficulty putting the pieces together. Does anyone know how I should do this? No vague replies please because I already have lots of vague ideas. Cheers.

Share this post


Link to post
Share on other sites
Advertisement
Well, you can set a property on swing menus so that they are heavyweight (PopupMenu.setDefaultLightWeightPopupEnabled( false ); )

AFAIK a canvas is always heavyweight and it's the only possibility to render from a native application. Currently I'm working on a Java3D app and I have the same goal: use a JPanel instead of an awt canvas directly.

Java3D has a JCanvas3D which extends JPanel and uses the real canvas internally (keyword offscreen rendering). The internal canvas renders to a buffered image (not directly but via some delegation) which then is draw to the JPanel.

Since Java3D is open source, you might want to have a look into their JCanvas3D class implementation. However, there seem to be some problems with linux drivers, that I'm currently facing (offscreen rendering crashes my JVM, but only on a specific machine - which is my development machine, however [sad] ).

Share this post


Link to post
Share on other sites
I would do two things.

1. I would use a form of active rendering for drawing the images in Java. The problem that I have run into with active rendering is that it is very fast with heavy weight components, but then you can't use swing, because mixing heavy and lightweight components doesn't work.

If you haven't already, look at the active rendering tutorial, which also has lots of links on the bottom. I would also suggest reading the forum posts for the article, because they talk about the swing problem, and some people have posted additional code examples.

http://www.gamedev.net/reference/programming/features/javarender/

2. For using Java and C++, I like swig. You could easily create a simple C++ that wraps the Irrlicht functions that you need, and then use Swig to automatically generate the JNI code. It saves a lot of time, and I bet there is information about getting a byte[] from C++ to Java.

The last time I did something like this, I was getting PNG files over an internet connection and displaying them in a JPanel, and I was getting about 60 FPS.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!