A collection of code snippets for the lazy libGDX user.
- Aimed for desktop projects, so the code won't run on HTML5 and mobile.
- Written/compiled with JDK 8, and uses Java 1.8 language features. Be advised you may encounter heavy (ab)use of lambdas.
- Invades the
com.badlogic.gdx.*
namespace. - Embeds a small native library for some utility functions.
- (Almost) no external dependencies besides libGDX.
- AnnotatedJson: custom JSON serializer, based on libGDX' Json classes, which allows annotation-driven serialization of object hierarchies.
- AutoDisposer: annotation-driven, semi-automatic disposal of disposable object hierarchies.
- GL33Ext: native interface to flextGL to expose desktop OpenGL functions not made available by libGDX/LWJGL.
- GLSLOptimizer: Native interface to glsl-optimizer.
- MultiTargetFrameBuffer: custom GLFrameBuffer implementation for creating multi-render targets, e.g. usable for deferred rendering (G-buffers).
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 {
@Override
public void create() {
GdxSnippetsNativesLoader.load();
}
}
This is a Maven project. Just use mvn package
or mvn install
to create a snapshot.
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 VS2013
> ./fips set config win64-vs2013-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. viamvn 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-vs2013
# or, for OS X
> mvn install -Posx-xcode
Note: this copies the compiled runtime library to
[libgdx-snippets]/src/main/resources
.