v0.1.0 · C++17 · OpenGL · MIT

The 2D game engine that gets out of your way.

cangine is a lightweight C++ engine built on OpenGL. Open a window, render quads & text, play audio, build UIs, and compose objects with a clean component system — no bloat, no ceremony.

4 UI objects// out of the box
9 examples// incl. mini-games
main.cpp
#include "cangine/cangine.hpp"

using namespace cangine;

class MyApp : public CangineApp {
public:
  MyApp() : CangineApp(800, 600, "My Game") {}

  void onFirstFrame() override {
    Label* hello = instantiateObject<Label>("Hello, world!");
    // Z index 80+ is the UI layer
    Transform::posFor(hello, Vector3(hello->getSize() / -2, 80));
  }

  void onFrame(double dt) override {
    // per-frame game logic
  }
};

int main() { MyApp().run(); }
What's inside

Everything a 2D game needs.
Nothing it doesn't.

A focused toolkit — rendering, audio, input, UI and a component system — assembled so you can ship a prototype today and grow it tomorrow.

Component system

Attach & detach Transform, renderers and your own components on any GameObject at runtime.

2D rendering

Colored & textured quads, triangles and FreeType text, batched through a clean OpenGL pipeline.

Built-in UI

Label, Button, InputField & Panel with click / return handlers, placeholders and styling.

Audio playback

Load & control sounds via AudioManager — play, pause, seek, volume & looping, powered by miniaudio.

Collision detection

SAT-based rect overlap and point-in-rect checks — fully aware of rotation and scale.

Input handling

Frame-accurate keyboard (getKey/Down/Up) and rich mouse events: click, move, scroll, enter.

Camera & layers

A movable Camera object you control with custom components, plus a simple Z-index layering model.

FPS & delta time

getFPS(), getInstantFPS() and getDeltaTime() right on the window for smooth, framerate-independent motion.

Shaders & textures

Minimal-boilerplate GLSL shader management and PNG/JPEG texture loading through stb_image.

Quick start

From clone to game loop in four steps.

The Makefile wraps CMake, so a single command builds the engine or runs any bundled example.

1

Install system deps

GLFW, GLAD, FreeType & fontconfig — only stb_image & miniaudio ship in-tree.

2

Clone the repo

One git clone and you have the engine plus nine examples.

3

make engine

Builds the static library via CMake into build/.

4

Subclass CangineApp

Override onFirstFrame() / onFrame(dt) and call .run().

# 1 · install dependencies
$ sudo apt install libglfw3-dev libfreetype-dev \
                   libepoxy-dev libfontconfig-dev

# 2 · clone & build the engine
$ git clone https://github.com/huseyinhealth/cangine.git
$ cd cangine && make engine

# 3 · build & run any example
$ make example EXAMPLE=sandbox
→ launching sandbox… 60 FPS ✓
api.cpp — explore the API
// A clickable button
Button* btn = instantiateObject<Button>("Click me!");
btn->registerOnClickEvent([&](const MouseEvent* e){
  score++;
});

// A text input with a submit handler
InputField* field = instantiateObject<InputField>();
field->setPlaceholder("Name?");
field->setOnReturn([&](std::string v){ name = v; });
// Load once, control anytime
audioMan->add("./music.mp3", "bgm");
audioMan->play("bgm", true);     // looping
audioMan->setVolume("bgm", 0.5f);
audioMan->seek("bgm", 10.0f);    // seconds

bool on = audioMan->isPlaying("bgm");
// Held down this frame
if (Input::getKey(Key::A)) player.x -= speed * dt;

// Pressed exactly this frame
if (Input::getKeyDown(Key::Space)) jump();

// Released this frame
if (Input::getKeyUp(Key::Escape)) pause();
// Point-in-rect — respects rotation & scale
bool hit = Rectangle::containsPoint(rect, tf, mousePos);

// Rect vs rect — SAT, transform-aware
bool col = Rectangle::overlaps(a, tfA, b, tfB);

if (col) onCollision();
Under the hood

A tidy, layered architecture.

Each subsystem lives behind a small, readable interface — engine, platform, render and audio, cleanly separated.

engine/
  • GameObject
  • ObjectManager
  • IComponent
  • Transform
  • QuadRenderer
  • TextRenderer
  • ui/ Label · Button
platform/
  • Window
  • Input
  • Key
  • Mouse
  • frame loop · FPS
render/
  • RenderSystem
  • QuadRenderer
  • TextRenderer
  • PrimitiveRenderer
  • Shader · Texture
  • VAO · VBO · EBO
audio · types · util
  • AudioManager
  • Sound
  • Vector2 · Vector3
  • Rectangle · Triangle
  • Color · Position
  • Dimensions
bundled · stb_image bundled · miniaudio install · GLFW install · GLAD install · FreeType install · fontconfig

stb_image & miniaudio ship in-tree — the rest are system packages (one apt command, below).

Learn by example

Nine examples ship in the box.

From a one-screen hello world to complete mini-games — every subsystem demonstrated in real, runnable code.

// basics$ make example
EXAMPLE=helloworld

helloworld basics

The minimal CangineApp — a window with centered text.

// ui$ make example
EXAMPLE=ui

ui & panel ui

Buttons, labels and containers wired up with event handlers.

// game$ make example
EXAMPLE=aimtrainer

aimtrainer game

A complete click-the-target mini-game with scoring.

// game$ make example
EXAMPLE=survival

survival game

Movement, spawning and collision in a survival loop.

// camera$ make example
EXAMPLE=camera

camera camera

A draggable camera panning across a world of quads.

// demo$ make example
EXAMPLE=sandbox

sandbox demo

The full-featured test scene exercising the whole engine.

Stop fighting your tools.
Start making games.

cangine is free, open source under MIT, and ready to clone right now.