Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

A collection of code snippets for use with libGDX.

License

Notifications You must be signed in to change notification settings

code-disaster/libgdx-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libGDX snippets

A collection of code snippets for the lazy libGDX user.

About

Aim

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!

Outline

  • 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.

Highlights

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.

  • 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.
  • MultiTargetFrameBuffer: custom GLFrameBuffer implementation for creating multi-render targets, e.g. usable for deferred rendering (G-buffers).

Usage

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(
            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.

About

A collection of code snippets for use with libGDX.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages