A small library for rendering Pixel Art with OpenGL 4.1 and playing sounds with OpenAL 1.1 based on LWJGL 3 and JOML.
Version | |
---|---|
JDK | 21 |
OpenGL | 4.1 |
OpenAL | 1.1 |
<dependency>
<groupId>io.github.mwttg</groupId>
<artifactId>pixel-artillery-2d</artifactId>
<version>1.0.0</version>
</dependency>
final OpenGlConfiguration config = new OpenGlConfiguration("My Window", 1920, 1080, true, true, 0.01f, 100.0f);
final GamwWindow myWindowId = GameWindow.create(config);
// a static sprite without animation
final Sprite staticSprite = StaticSprite.create(1.0f, 1.0f, "./data/static-sprite.png");
// an animated Sprite with 3 Frames
final Sprite animatedSprite = AnimatedSprite.create(1.0f, 1.0f, "./data/animated-sprite.png", List.of(150, 150, 200));
final int myShaderProgramId = ShaderProgram.createFrom("./shader/vertex.glsl", "./shader/fragment.glsl");
final Uniform myUniform = Uniform.create(myShaderProgramId);
// or you can use the default ShaderProgram
final int defaultShaderProgramId = ShaderProgram.createDefaultShader();
final int defaultUniform = Uniform.create(defaultShaderProgramId);
while (!GLFW.glfwWindowShouldClose(myWindowId)) {
GL41.glClear(GL41.GL_COLOR_BUFFER_BIT | GL41.GL_DEPTH_BUFFER_BIT);
GL41.glUseProgram(myShaderSprogramId);
staticSprite.draw(myUniform, model1Matrix, viewMatrix, projectionMatrix);
animatedSprite.draw(myUniform, model2Matrix, viewMatrix, projectionMatrix);
GLFW.glfwSwapBuffers(myWindowId);
GLFW.glfwPollEvents();
}
Or you can use the abstract class SimpleApplication
.
An example can be found here.
Why OpenGL 4.1?
It is the last version which is supported by Mac/Apple. So this lib can be used without complicated setup stuff.
What texture filtering is used for the Sprites?
This library is build for pixel art.
That means there is no antialiasing for textures instead it is 'pixel perfect'.
In detail the GL_TEXTURE_MIN_FILTER
is set to GL_NEAREST_MIPMAP_NEAREST
and the GL_TEXTURE_MAG_FILTER
is set to GL_NEAREST
.
Is there example code that uses this library?
Yes. see: https://github.com/mwttg-games/pixel-artillery-2d-test for graphics and sound example.