Jme-Graphics Handler


#1

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.


#2

This is great, thank you for sharing this!


#3

Great, Thanks for sharing :slightly_smiling_face:


#4

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);

#5

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