A cross-platform 2D game engine for Java, built on LWJGL.
Garnet is still in development but the main functionality is all working. Feedback is really useful at this stage, so please feel free to create a small project and let me know how you get on.
- Timed Game Loop
- 2D Sprite and sprite sheets
- Primitive drawing - circle, rectangle, lines
- Texture loading
- Input handling
- Font drawing
- Tile map support
- Sound player
- Game ToolKit
<dependency>
<groupId>io.github.nickd3000</groupId>
<artifactId>garnet</artifactId>
<version>0.6.0</version>
</dependency>See the garnet-examples project for examples.
This small example loads and draws a texture to the display.
import com.physmo.garnet.Garnet;
import com.physmo.garnet.GarnetApp;
import com.physmo.garnet.graphics.Graphics;
import com.physmo.garnet.graphics.Texture;
// NOTE: on MacOS we need to add a vm argument: -XstartOnFirstThread
public class SimpleSpriteExample extends GarnetApp {
Texture texture;
public SimpleSpriteExample(Garnet garnet, String name) {
super(garnet, name);
}
public static void main(String[] args) {
Garnet garnet = new Garnet(600, 400);
GarnetApp app = new SimpleSpriteExample(garnet, "");
garnet.setApp(app);
garnet.init();
garnet.run();
}
@Override
public void init(Garnet garnet) {
texture = Texture.loadTexture("garnetCrystal.png");
garnet.getGraphics().addTexture(texture);
}
@Override
public void tick(double delta) {
}
@Override
public void draw(Graphics g) {
int[] mousePosition = garnet.getInput().getMousePosition();
g.drawImage(texture, mousePosition[0], mousePosition[1]);
}
}- Version moved from 0.5.3 in January 2025 to current 0.5.10a-SNAPSHOT.
- Added tick-rate control in Garnet via getTickRate() / setTickRate(double).
- Added shader/post-processing support: ShaderProgram, RenderTexture, internal buffer mode, optional buffer shader, and many shader examples/resources.
- Added advanced graphics examples: CRT, glow, blur, palette, film grain, dissolve, hue shift, outline, chromatic aberration, underwater, wave, colour grading.
- Added per-element blend modes in DrawableBatch using BlendMode.
- Added drawable color override support.
- Refactored viewport/scrolling behavior, including renamed scrolling-related methods and updated transform handling.
- Added toolkit messaging: Context, GameObject, and Component can send/broadcast messages, with MessageListener.
- Collision system substantially improved: collision groups/matrix, BucketGridMap, lower allocations, group-based queries, and removeColliderFromGameObject.
- Particle system improved: gravity support, default emission curve, and corrected centered jitter behavior.
- Array gained more utility methods and performance-oriented improvements.
- TileSheet / SubImage usage was optimized to reduce allocations; tile index lookup from 2D coordinates was added.
- Fixed Vector3.getAngle and added VectorAngleExample.
- Examples moved from com.physmo.garnetexamples to com.physmo.reference.
- LWJGL updated to 3.3.6; mouse cursor handling optimized.
- Javadocs/API docs expanded heavily across the public API.
- Allow tick rate control in core Garnet class
- CollisionSystem - added removeColliderFromGameObject()
- Add gravity support to particles
- Convert some graphics classes that use SubImage to use an output parameter to help avoid allocations.
- Improvements to collision - Reduce memory allocations by reusing structures
- Moved examples to reference folder
- Added additional functionality to Array class
- GameObject method to retrieve all components.
- SceneManager method to retrieve a scene by Name
- Improvements to the window scaling code.
- Added full screen toggle to Display
- Timer and monitoring changes
- Added Array class to reduce heap use.
- Renamed camera system to viewport
- Moved to Java 17
- Added Surefire Plugin
- Added Spock tests
- Improved documentation
- Brought Toolkit project into Garnet project
- Added getAngle method to Vector3 class
- Added Inline Texture creator
- Split input system into sub systems for mouse and keyboard
- Allow Raw access to keyboard
- Document input systems better
- Fix TileGridDrawer not drawing tiles past the right and bottom edges
- Camera support has been added to the graphics system
- Cameras support panning, zooming and clipping
- TileGridDrawer updated to use new camera system
- API add: rgbToFloat method that is passed output list to reduce new objects creation.
- API add: Font scaling
- API add: Added Animation class
- API add: Added normalized (0..1) mouse coordinate method to Input
- API add: Added SubImage class which describes a sub area of a texture
- API add: Added SubImage supplier to TileSheet class
- API add: Added volume controls for sound playback
- API add: Allow window title to be changed - Display.setWindowTitle(String)
- Optimized sprite drawing - added Sprite2D object pool to reuse sprite objects.
- Package refactoring
- Rewrote paragraph drawer and fixed new line bugs.
