jME and Graphics2D

I work in a small game developer company in Norway, and we are currently working on

a Java based game.



The current graphics engine we have is based on Java's Graphics2D, but we would like to include

some 3D elements in the game. However, we do not wish to rewrite the entire engine (an isometric

tile-based engine plus a lot of 2D GUI etc.). Would it be possible to write a 3D scene within

the jME framework, and then paint it into a Graphics2D-environment?



What I currently have in mind, altough it may not be the best solution, is that the 3D jME scene

(or several scenes at once) has it's own thread(s) and does all the updating by itself.

Then, when needed to, the old graphics engine could call a method to paint the 3d scene

into a Graphics2D object.



Does anyone have some experience with this kind of problem? Does anyone know of any helpful resources?



Any help would be great! :slight_smile:

Howdy, and welcome :slight_smile:



I think the (hopefully to be included soon), context system created by Momoko_Fan, would work for you here…

http://www.jmonkeyengine.com/jmeforum/index.php?board=15.0

You should reverse the solution, instead of painting the 3D onto the Graphics2D, paint your 2D stuff to an ImageGraphics (which sends it automatically as a texture to OGL) and then use that as your background to the 3D stuff. Also, basixs, I think you misunderstood the purpose of the context system…

basixs said:

I think the (hopefully to be included soon), context system created by Momoko_Fan, would work for you here...
http://www.jmonkeyengine.com/jmeforum/index.php?board=15.0


Thanks, i'll look into it :)

Momoko_Fan said:

You should reverse the solution, instead of painting the 3D onto the Graphics2D, paint your 2D stuff to an ImageGraphics (which sends it automatically as a texture to OGL) and then use that as your background to the 3D stuff. Also, basixs, I think you misunderstood the purpose of the context system..


I know thats probably the right way to do it, and for future projects this may be the solution. However, the less code I have to rewrite for the current project, the better.
I know thats probably the right way to do it, and for future projects this may be the solution. However, the less code I have to rewrite for the current project, the better.

Okay, do note however that doing it that way would cause a large performance penalty especially for large resolutions due to framebuffer having to round-trip from CPU & GPU. Create an RGBA8 Pixel Buffer using the context system and paint your 3D stuff onto it, retrieve the data using getImage() then convert to a BufferedImage, paint that onto your Graphics2D.

If you try this and the performance loss is unbearable, doing it the other way should help a lot:
Replace the JPanel or w/e you're using with a jME canvas, paint the 2D stuff into the Graphics2D given in ImageGraphics, use the provided texture on a full-screen quad. Render the quad, clear the Z buffer then render your 3D stuff.
Also, basixs, I think you misunderstood the purpose of the context system..

I guess your right, I assumed that since it help facilitate off-screen rendering (i think, haven't used it yet) that it would also facilitate 'getting' the stuff back out of the v-card... 
Momoko_Fan said:

Replace the JPanel or w/e you're using with a jME canvas, paint the 2D stuff into the Graphics2D given in ImageGraphics, use the provided texture on a full-screen quad. Render the quad, clear the Z buffer then render your 3D stuff.


That sounds like it would be pretty easy to implement. I'll give it a go, thanks a lot!