Haaf’s Game Engine — HGE — occupies a specific and valuable niche in the 2D engine landscape. It’s not trying to be everything to everyone. It’s a focused, C++-based framework for hardware-accelerated 2D rendering, with a clean API that doesn’t hide what’s happening underneath.

We maintain the HGE documentation portal here at Relish Games, and we regularly hear from developers who are curious about HGE but unsure how to get started. This guide covers the practical steps from download to rendering your first sprites.

Why HGE in 2026?

Before diving into setup, it’s worth understanding what makes HGE relevant when there are dozens of engine options available:

  • Direct hardware access: HGE uses DirectX for rendering, giving you close-to-metal performance without managing GPU state yourself
  • Small footprint: The entire engine is compact enough to understand completely — no mysterious black boxes
  • C++ native: If C++ is your language, HGE feels natural. No scripting layers, no VM overhead
  • Focused scope: Sprite rendering, particle effects, audio, input — the core needs of 2D games without scope creep
  • Active documentation: The comprehensive API reference covers every function and constant

The tradeoff is real: HGE is Windows-focused and requires C++ competence. If you need cross-platform from day one or prefer higher-level languages, other engines may be more appropriate. But if you’re building a Windows 2D game in C++ and want maximum control with minimum overhead, HGE is hard to beat.

Getting Set Up

Prerequisites

  • Visual Studio 2022 or later (Community edition works fine)
  • Windows 10/11 SDK (included with Visual Studio)
  • C++ knowledge: You should be comfortable with pointers, classes, and basic memory management
  • DirectX runtime: Usually already present on modern Windows installs

Download

Head to the HGE downloads page and grab the latest package. The download includes:

  • Core engine libraries (static and dynamic linking options)
  • Header files
  • Sample projects
  • Particle editor tool
  • Documentation

Project Setup

  1. Create a new empty C++ project in Visual Studio
  2. Add the HGE include directory to your project’s include paths
  3. Add the HGE library directory to your linker paths
  4. Link against hge.lib and hgehelp.lib
  5. Copy hge.dll to your output directory

The Core Loop

HGE’s architecture revolves around a simple and effective pattern: you provide callback functions, and the engine calls them at the right times.

Minimal Application

The skeleton of every HGE application:

#include <hge.h>

HGE *hge = nullptr;

bool FrameFunc()
{
    // Game logic goes here
    // Return true to exit the application
    if (hge->Input_GetKeyState(HGEK_ESCAPE))
        return true;
    
    return false;
}

bool RenderFunc()
{
    hge->Gfx_BeginScene();
    hge->Gfx_Clear(0);
    
    // Rendering goes here
    
    hge->Gfx_EndScene();
    return false;
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    hge = hgeCreate(HGE_VERSION);
    
    hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
    hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
    hge->System_SetState(HGE_TITLE, "My First HGE Game");
    hge->System_SetState(HGE_WINDOWED, true);
    hge->System_SetState(HGE_SCREENWIDTH, 800);
    hge->System_SetState(HGE_SCREENHEIGHT, 600);
    hge->System_SetState(HGE_USESOUND, false);
    
    if (hge->System_Initiate())
    {
        hge->System_Start();
    }
    
    hge->System_Shutdown();
    hge->Release();
    
    return 0;
}

This gives you a window with a clear screen and an escape key to quit. Not exciting yet, but the structure is important.

Understanding the Flow

The System_Initiate call sets up the window and rendering context. System_Start enters the main loop, which calls your FrameFunc for logic and RenderFunc for drawing every frame. System_Shutdown cleans up when you’re done.

The system state constants control everything from window size to audio settings to logging behaviour. Get comfortable with these — they’re your primary configuration mechanism.

Loading and Rendering Sprites

The core of any 2D game is getting images on screen. HGE makes this straightforward:

HTEXTURE tex;
hgeSprite *sprite;

// In your initialisation:
tex = hge->Texture_Load("player.png");
sprite = new hgeSprite(tex, 0, 0, 64, 64);
sprite->SetHotSpot(32, 32); // Center the origin

// In your render function:
sprite->Render(400, 300); // Draw at position (400, 300)

The hgeSprite class handles texture mapping, colour modulation, rotation, and scaling. It’s the building block for everything visual.

Sprite Sheets and Animation

For animated characters, you’ll work with sprite sheets — single textures containing multiple animation frames:

// Create sprites for each frame
hgeSprite *walkFrames[4];
for (int i = 0; i < 4; i++)
{
    walkFrames[i] = new hgeSprite(tex, i * 64, 0, 64, 64);
}

// In frame function, advance animation
animTimer += hge->Timer_GetDelta();
if (animTimer > 0.1f) // 10 fps animation
{
    currentFrame = (currentFrame + 1) % 4;
    animTimer = 0;
}

// In render function
walkFrames[currentFrame]->Render(playerX, playerY);

The Particle System

One of HGE’s standout features is its built-in particle system. Particle effects — explosions, fire, magic spells, ambient dust — add tremendous visual richness with minimal code:

hgeParticleSystem *particles;

// Load a particle preset (created with the particle editor)
particles = new hgeParticleSystem("explosion.psi", sprite);
particles->Fire();

// In frame function
particles->Update(hge->Timer_GetDelta());

// In render function
particles->Render();

The particle editor included with HGE lets you design effects visually and export presets. This workflow — visual editing for creative work, code for integration — is one of HGE’s strongest practical features.

Audio Basics

HGE includes audio support for both sound effects and music:

// Enable sound in system state
hge->System_SetState(HGE_USESOUND, true);

// Load and play
HEFFECT snd = hge->Effect_Load("laser.wav");
hge->Effect_Play(snd);

// Music (streaming)
HSTREAM music = hge->Stream_Load("theme.ogg");
hge->Stream_Play(music, true); // true = loop

The music playback functions support streaming from disk, which is essential for background music that shouldn’t consume memory.

Resource Management

As your project grows, managing textures, sounds, and other assets manually becomes unwieldy. HGE provides a resource management system that loads resources from script files:

; resources.res
Texture player   = player.png
Texture enemies  = enemies_sheet.png
Sound   laser    = sfx/laser.wav
Music   theme    = music/main_theme.ogg

This keeps resource paths out of your code and makes it easy to swap assets without recompiling.

Common Patterns

Delta Time Movement

Always multiply movement by delta time for frame-rate-independent motion:

float dt = hge->Timer_GetDelta();
playerX += velocityX * dt;
playerY += velocityY * dt;

Blend Modes

HGE’s blend mode system controls how sprites combine with the background. Additive blending for glowing effects, alpha blending for transparency, multiplicative for shadows.

Render Lines and Primitives

For debugging or minimalist visuals, Gfx_RenderLine draws lines directly. Useful for collision boxes, pathfinding visualisation, and HUD elements.

  1. Get the minimal app running — window, clear screen, quit on escape
  2. Load and render a single sprite — understand texture loading and coordinate systems
  3. Add movement and input — keyboard/mouse driven sprite movement
  4. Explore particles — fire up the particle editor and integrate effects
  5. Add audio — sound effects on actions, looping background music
  6. Build a tiny game — Pong, breakout, or a simple shooter to exercise all the systems together

The HGE overview page provides context for how these pieces fit together, and the demo collection shows finished examples of each feature.

What Comes Next

Once you’re comfortable with the basics, HGE supports more advanced techniques:

  • Custom shaders for visual effects
  • Distortion meshes for water, heat haze, and warping
  • Texture render targets for post-processing
  • Collision detection using sprite bounding boxes and pixel-perfect methods

The engine gives you the primitives. What you build with them is up to you.

Visit the full HGE documentation for the complete API reference, explore the demos for inspiration, or join the forum to connect with other HGE developers.