🎮 A simple 2D game framework written in Rust
Switch branches/tags
Nothing to show
Clone or download
17cupsofcoffee Add SDL2.dll to .gitignore
I'll just check it in by accident otherwise...
Latest commit bbd39e9 Dec 10, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Remove unused example files Dec 10, 2018
src Implement text rendering (#17) Dec 9, 2018
.gitignore Add SDL2.dll to .gitignore Dec 10, 2018
CHANGELOG.md Fix wrong header level in changelog Dec 9, 2018
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Dec 6, 2018
Cargo.toml Release 0.1.6 Dec 9, 2018
LICENSE Initial commit Sep 30, 2018
README.md Implement text rendering (#17) Dec 9, 2018



Crates.io Documentation License

Tetra is a simple 2D game framework written in Rust. It uses SDL2 for event handling and OpenGL 3.2+ for rendering.

Note that Tetra is still extremely early in development! It may/will have bugs and missing features (the big ones currently being sound and gamepad support). That said, you're welcome to give it a go and let me know what you think :)


  • XNA/MonoGame-inspired API
  • Efficient 2D rendering, with draw call batching by default
  • Animations/spritesheets
  • Pixel-perfect screen scaling
  • Deterministic game loop, à la Fix Your Timestep.


To add Tetra to your project, add the following line to your Cargo.toml file:

tetra = "0.1"

You will also need to install the SDL2 native libraries, as described here.


To get a simple window displayed on screen, the following code can be used:

extern crate tetra;

use tetra::graphics::{self, Color};
use tetra::{Context, ContextBuilder, State};

struct GameState;

impl State for GameState {
    fn update(&mut self, _ctx: &mut Context) {}

    fn draw(&mut self, ctx: &mut Context, _dt: f64) {
        // Cornflour blue, as is tradition
        graphics::clear(ctx, Color::rgb(0.392, 0.584, 0.929));

fn main() -> tetra::Result {
    let ctx = &mut ContextBuilder::new()
        .title("Hello, world!")

    let state = &mut GameState;

    tetra::run(ctx, state)

You can see this example in action by running cargo run --example hello_world.

The full list of examples available are:

  • hello_world - Opens a window and clears it with a solid color.
  • texture - Loads and displays a texture.
  • animation - Displays an animation, made up of regions from a texture.
  • text - Displays text using a TTF font.
  • nineslice - Slices a texture into nine segments to display a dialog box.
  • keyboard - Moves a texture around based on keyboard input.
  • mouse - Moves a texture around based on mouse input.
  • tetras - A full example game (which is entirely legally distinct from a certain other block-based puzzle game cough).


As mentioned above, Tetra is fairly early in development, so there's likely to be bugs/flaky docs/general weirdness. Please feel free to leave an issue/PR if you find something!

You can also contact me via Twitter, or find me lurking in the #gamedev channel on the Rust Community Discord.