Jme-Graphics Handler

JME-Graphics

Download

implementation 'com.jayfella:jme-graphics:1.1.1'

The first of many libraries I’ll be uploading to jcenter. To use it, just add this dependency to your gradle project.

A global graphics object for jmonkey to allow modifying the various graphics configurations at any time during your game.

  • Enable/disable post-processing effects easily.
  • Manipulate camera view-frustum and field-of view.
  • Set anistropic filtering level with a single line of code.
  • Change resolution, frame-rate, vsync, etc… at any time in your game.
  • Get the camera depth texture.

public class Main extends SimpleApplication {

    public static void main(String... args) {
        
        Main main = new Main();
        main.start();
    }

    @Override
    public void simpleInitApp() {

        Graphics.initialize(this);

        // Enable Anistripic Filtering
        Graphics.getInstance().setAnistropicFilteringLevel(PowerLevel.SIXTEEN);
        
        // change some camera settings
        Graphics.getInstance().getCameraSettings().setFieldOfView(70);
        Graphics.getInstance().getCameraSettings().setFrustumFar(1000);
        
        // enable some built-in post-processing filters
        Graphics.getInstance().getPostProcessor().setAmbientOcclusionEnabled(true);
        Graphics.getInstance().getPostProcessor().setFxaaEnabled(true);
        
        // enable an effect you made yourself
        Graphics.getInstance().getPostProcessor().setFilterEnabled(MyFilter.class, true);
        
        // get a filter
        BloomFilter bloomFilter = Graphics.getInstance().getPostProcessor().getBloomFilter();
        MyFilter myFilter = Graphics.getInstance().getPostProcessor().getFilter(MyFilter.class);
        
        
        // modify any context settings
        
        // since we enable FXAA we also need to set the strength.
        Graphics.getInstance().getContextSettings().setNumSamples(PowerLevel.EIGHT);
        
        Graphics.getInstance().getContextSettings().setResolution(1280, 720);
        Graphics.getInstance().getContextSettings().setFrameRate(120);
        
        // any time we change getContextSettings settings we must apply them.
        // we "apply" manually so we can chain settings before applying them.
        Graphics.getInstance().getContextSettings().apply();

        // Get the camera depth texture and use it in a material
        Texture2D depthTexture = Graphics.getInstance().getCameraSettings().getDepthTexture();
        myMaterial.setTexture("DepthTexture", depthTexture);

    }

}

Source code is available as always on github.

https://github.com/jayfella/jme-graphics

12 Likes

This is great, thank you for sharing this!

1 Like

Great, Thanks for sharing :slightly_smiling_face:

1 Like

Updated to v1.0.2

I’ve added some javadoc while I was there, but the only addition is being able to easily get the depth texture of the main camera. It’s lazily loaded, so it only starts generating it upon first request.

Texture2D depthTexture = Graphics.getCameraSettings().getDepthTexture();
myMaterial.setTexture("DepthTexture", depthTexture);

Maybe we should pin this topic to be on top of forum page for a while ?

@jayfella
You should put this on the store.
:smiley:

5 Likes

I wanted to say the same, in the store we can find it easier than here in the forum buried below a bunch of topics. Looks awesome, something I always struggle just nicely packed and read to use.

I’m sure he hasn’t forgotten the store, just takes time to get a nice post written up. Or maybe the store admin rejected it. :wink:

2 Likes

I will add it, just have a busy day or two in front ot me at the minute.

3 Likes