Shaders in libgdx

This is not a tutorial article i just wanted to post about my first try of using shaders with libgdx. Here’s the code

pretty slick, eh :). The output of this is the following amazing image:

Granted, the shader is not very complex. What’s more important though is how easy it is to use with an instance of Mesh, the class i rewrote today. It will replace FloatMesh, FixedPointMesh and MeshRenderer as i came to the conclusion that having a seperate MeshRenderer only complicates matters. This Mesh class has a pretty nifty mechanism called VertexAttributes. If you remember how the constructor of the old FloatMesh/FixedPointMesh looked like you’ll see quiet some differences. You now how to specify so called VertexAttributes which together define the components of a vertex, e.g. position, color, normal as well as the components’ order within one vertex. If you use the fixed function pipeline of OpenGL ES 1.x you specify how that attribute should be used, e.g. whether it’s a position, color, normal and so on. If you use the same Mesh with OpenGL ES 2.x the usage is ignored and the name of the attribute becomes important. The name should be equal to the attribute in your vertex and fragment shaders so that the Mesh class can automatically bind the attribute to the proper location upon a call to Mesh.render(). Now i can finally start working with nifty shaders :).

The same code works seamlessly on Android of course 🙂

One thought on “Shaders in libgdx

Leave a Reply

Your email address will not be published.