Texture Assembler

Create texture atlases from multiple source images.

Overview

The Texture Assembler (TexAsm) combines multiple small images into a single large texture atlas. This improves rendering performance by reducing texture switches.

Benefits of Texture Atlases

  • Fewer state changes — GPU works more efficiently with fewer texture binds
  • Batch rendering — Sprites from the same atlas can be batched together
  • Reduced memory waste — Power-of-two padding is shared among images
  • Faster loading — One file load instead of many

Usage

The texture assembler is a command-line tool:

texasm <script_file> <output_image> [output_description]

Script Format

Create a text file listing the source images:

; Comment lines start with semicolon
images/player_idle.png
images/player_walk1.png
images/player_walk2.png
images/player_walk3.png
images/player_jump.png
images/bullet.png
images/enemy1.png
images/enemy2.png

Example Workflow

1. Create a script file sprites.txt:

gfx/hero_stand.png
gfx/hero_walk1.png
gfx/hero_walk2.png
gfx/hero_jump.png
gfx/coin.png
gfx/gem.png

2. Run the assembler:

texasm sprites.txt atlas.png atlas.txt

3. Load and use in your game:

HTEXTURE atlas = hge->Texture_Load("atlas.png");

// Use coordinates from atlas.txt
hgeSprite *heroStand = new hgeSprite(atlas, 0, 0, 32, 48);
hgeSprite *coin = new hgeSprite(atlas, 32, 0, 16, 16);

Output Description

The optional output description file contains the coordinates:

hero_stand  0  0  32 48
hero_walk1  32 0  32 48
hero_walk2  64 0  32 48
coin        96 0  16 16

Tips

  • Power of two — Output textures work best at power-of-two sizes (256, 512, 1024)
  • Organize by usage — Group sprites used together in the same atlas
  • Leave margins — Add 1-2 pixel spacing to prevent bleeding artifacts
  • Multiple atlases — Large projects may need several atlases

See Also