template<typename T, unsigned int N = 1>
OrbitEngine::Graphics::BitmapAtlas class

A 2D bitmap atlas.

Example: manually make an atlas of four 64x64 bitmaps

BitmapAtlasRGBA* atlas = new BitmapAtlasRGBA(128, 128);
atlas->addFrame(0, img1,  0,  0, false);
atlas->addFrame(1, img2, 64,  0, false);
atlas->addFrame(2, img3,  0, 64, false);
atlas->addFrame(3, img4, 64, 64, false);
atlas->exportToFiles("atlas.json", "atlas.png");
delete atlas;

Example: automagically make an atlas out of bitmaps

std::map<FrameIndex, BitmapRGBA> bitmaps;
bitmaps.emplace(0, img1);
bitmaps.emplace(1, img2);
bitmaps.emplace(2, img3);
bitmaps.emplace(3, img4);
BitmapAtlasRGBA* atlas = BitmapAtlasRGBA::Generate(bitmaps, 2048);
if (atlas) {
    atlas->exportToFiles("atlas.json", "atlas.png");
    delete atlas;
}

Currently, its not possible to load a BitmapAtlas from disk. Take a look into TextureAtlas for using it during runtime.

Base classes

class Atlas
Generic 2D atlas class.
template<typename T, unsigned int N = 1>
class Bitmap protected
A 2D bitmap image with N channels of elements T.

Public static functions

static auto Generate(const std::map<FrameIndex, std::pair<Bitmap<T, N>, FrameMetadata>>& bitmaps, unsigned int max_size, unsigned int padding = 0, const T background[N] = 0, bool POT = false) -> BitmapAtlas<T, N>*
Generate an atlas from bitmaps.

Constructors, destructors, conversion operators

BitmapAtlas(unsigned int w, unsigned int h)
Creates an empty WxH bitmap atlas.
~BitmapAtlas()

Public functions

auto getTexelSize() const -> Math::Vec2f override
Returns texel sizes in both dimensions (1.0f / size)
auto addFrame(FrameIndex index, const Bitmap<T, N>& bitmap, int x, int y, bool flip, FrameMetadata meta) -> bool
Add a bitmap frame at x, y.
auto exportToFiles(const std::string& metadata, const std::string& image) const -> bool
Export the bitmap atlas to disk.

Function documentation

template<typenameT, unsigned intN>
static BitmapAtlas<T, N>* OrbitEngine::Graphics::BitmapAtlas<T, N>::Generate(const std::map<FrameIndex, std::pair<Bitmap<T, N>, FrameMetadata>>& bitmaps, unsigned int max_size, unsigned int padding = 0, const T background[N] = 0, bool POT = false)

Generate an atlas from bitmaps.

Parameters
bitmaps in map containing the desired indexes mapped to their corresponding bitmaps and metadata
max_size in maximum allowed size for the generated atlas. The generation may fail if its not possible to fit the bitmaps
padding in separation in pixels between each bitmap in the atlas
background in color of the unused pixels
POT in force the atlas generation to be a power of two
Returns The BitmapAtlas instance or NULL if the operation failed

template<typenameT, unsigned intN>
bool OrbitEngine::Graphics::BitmapAtlas<T, N>::addFrame(FrameIndex index, const Bitmap<T, N>& bitmap, int x, int y, bool flip, FrameMetadata meta)

Add a bitmap frame at x, y.

Parameters
index in identifier within the atlas, must be unique
bitmap in Bitmap to write
in location to write the bitmap
in location to write the bitmap
flip in if the input bitmap must be rotated 90 degrees clockwise
meta in additional metadata
Returns Whether the frame was added correctly

template<typenameT, unsigned intN>
bool OrbitEngine::Graphics::BitmapAtlas<T, N>::exportToFiles(const std::string& metadata, const std::string& image) const

Export the bitmap atlas to disk.

Parameters
metadata in path to the metadata file to write (.json)
image in path to the image file to write (.png)
Returns Whether the atlas was exported correctly