Best way to do 2d graphics for a beginner

Hi

My background is in Processing, which is very easy to use for 2d drawing of squares and circles etc.

I want to do this in JME3 - what is the best way to go about this for a beginner,

Thanks,

Glenn.

1 Like

jME3 is best suited for high definition 3D graphics, not drawing squares and circles. It doesn’t mean it is not possible, its just has to be done manually. For square you can use the Quad mesh, but to draw a circle you’ll have to generate the mesh yourself.

You can also just use processing and then get the data as an image, and draw it with jME3 that way.

1 Like

Thanks, I want to mix 3d graphics with 2d graphics, for overlaying HUD elements etc, and also just generally want to able to draw 2d lines and shapes etc. I don’t know where to start, what libraries to use, how to even create a screen to draw into, do I have to set up screen buffers etc. I’ve looked around and seen mention of canvases, java2d and other things, but I’m just confused as a noob about getting the basics.

1 Like

Start by going through the tutorials, after you know what jME can do and how it does it it might be easier.

1 Like

I have gone through all the tutorials, but they are all 3d based, couldn’t find anything jme3 & 2d graphics related though. Is it java2d I should be using?

1 Like

Not “look at all the tutorials and search for your keyword” but “go through them and learn jme”…

You could use Java2d to paint and then copy over the data to some texture, kind of the reverse thing the TestRenderToMemory.java test does.

1 Like

I’m also having trouble with 2D graphics. JMonkey is a great 3D IDE, but the absence of a user friendly 2D interface is annoying. Designing an instrument panel for a Flight Simulator turns into a nightmare.

Any chance of a better 2D interface anytime soon ?

1 Like

Take a look at Lemur by @pspeed

1 Like

Take a look at Lemur by @pspeed

1 Like

That all depends on what you mean by “2D.” jME is inherently a 3D rendering engine. I highly doubt you will ever find “stroke a circle, fill a star, and apply a gradient behind them” type functionality in jME (you could do this by using other 2D libraries to produce a pixel buffer and use that as a texture in jME, however). That being said… for your specific case of making an instrument panel, I think you might find a 3D scene graph to be what you’re looking for. Keep in mind that there are two different types of cameras in jME: perspective (“normal” 3D with depth shortening, etc.) and orthogonal (parallel, no depth effect). An orthogonal rendering will look 2D because all of the mesh vertices will be “splatted” straight back onto the camera view without depth being taken into account. For example, to build a gauge you would need a circle mesh, a gauge background texture, a needle mesh, and a needle texture. To build your gauge, you just need to position and rotate your needle over the background circle. Your gauge can then be rendered either (a) in a perspective-correct instrument panel attached to your plane model, or (b) in the jME guiNode (“flat” against the screen).

1 Like

I found this post, which might help. Please note that it is based on older JMonkey version.

@Override
public void simpleInitApp() {
// setup camera for 2D games
cam.setParallelProjection(true);
cam.setLocation(new Vector3f(0,0,0.5f));
getFlyByCamera().setEnabled(false);

// turn off stats view (you can leave it on, if you want)
setDisplayStatView(false);
setDisplayFps(false);
}

1 Like

Thanks for that danielp, I will consider what you said. I’ve also looked at nifty, but your suggestion of generating meshes for the panel may be the way to go instead of learning another interface like Nifty.

1 Like

No problem… the cool thing about jME is that if you do your “2D” as a “flattened” 3D, you get a whole lot of advanced scene graph power for “free.” Plus, if you do your gauges and needles correctly, you can eventually add physically correct lighting and shadows, again for “free” - not something that’s easy to do with a 2D framework.

1 Like

that looks interesting setanath, I’ll investigate that too. :slight_smile:

1 Like

@pspeed also did a 2d vector shooter: https://github.com/jMonkeyEngine-Contributions/zay-es/tree/master/examples/AsteroidPanic

1 Like