libGDX snippets

A collection of code snippets for the lazy libGDX user.



This library is not a framework, nor an engine. It is just a collection of Java classes which might prove worth (re-)using in a libGDX desktop project.

Update policy

You may notice that commits are done at rather strange intervals. This code is extended and improved in conjunction with our current game development project at Robotality. I found Git submodules very cumbersome to work with, esp. when working in a team with artists and designers. That said, the main branch of this library is actually embedded in our game project, using this GitHub repository as a backup/mirror.

This means that changes done are pretty much instantly tested in our production environment, but commits to this public repository are often lagging behind, and are done in batches.

This also means that there can be API breaking changes at any time!



2018-Nov-28: I removed the native interfaces to GLSL Optimizer and Remotery. GLSL Optimizer didn't have any noticeable performance impact for our use cases, and isn't applicable to many of our shaders (GLSL > 150). The Remotery wrapper has been replaced by the more complete and well-maintained LWJGL Remotery bindings.


To use the native interfaces, you just need to add a call to GdxSnippetsNativesLoader.load(), for example in your create() function.

public class MyGdxGameAdapter extends ApplicationAdapter {
    public void create() {
            true /* load native library */,
            true /* setup GL function bindings using flextGL *);

Building from source

Java package

This is a Maven project. Just use mvn package or mvn install to create a snapshot.

Native libraries

This library uses the fips cmake build wrapper to compile the native source code. Please read the list of requirements to run fips (in short: Python 2.7.9, cmake 2.8.11+, and an appropriate C++ compiler environment). In addition, Maven and Java are required for the fips-jni module.

The steps below should work on every target system. You only need to specify a different build target.

The root folder for the native code is located in [libgdx-snippets]/src/main/native/jni/.

# navigate to the native source folder
> cd [libgdx-snippets]/src/main/native/jni/

To install fips plus dependencies (one-time):

# this will install fips
> ./fips

# fetch dependencies
> ./fips fetch

# setup fips-jni
> ./fips jni setup

To select the build target (one-time):

# [optional] list all configs known to fips
> ./fips list configs

# e.g. for Windows 64 bit, using VS2017
> ./fips set config win64-vs2017-release

# or, for OS X, using XCode
> ./fips set config osx-xcode-release

To compile the native library:

# [optional] clean output
> ./fips clean all

# generate JNI code and build the library
> ./fips build

Note: fips-jni uses gdx-jnigen to generate native code from C++ embedded in Java source files. Gdx-jnigen parses both .java and .class files. This means that, to compile the native library successfully, it is required to compile the Java code first, e.g. via mvn compile from the root folder, or from inside your favourite IDE.

To copy the compiled runtime library:

# e.g. for Windows 64 bit
> mvn install -Pwin64-vs2017

# or, for OS X
> mvn install -Posx-xcode

Note: this copies the compiled runtime library to [libgdx-snippets]/src/main/resources.