All Projects → mborgerson → textureatlas

mborgerson / textureatlas

Licence: MIT license
A simple, cross-platform Python-based tool and C library for creating and using a texture atlas in your application or game. Distributed under the terms of the MIT license.

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to textureatlas

UnityHFSM
A simple yet powerful class based hierarchical finite state machine for Unity3D
Stars: ✭ 243 (+1115%)
Mutual labels:  gamedev
faur
⚒️✨ My personal C games framework. 2D graphics, sound, inputs, states, ECS, and misc utils for data, files, math, memory, strings, time, and more. Builds for Linux, Windows, Web, and embedded devices.
Stars: ✭ 55 (+175%)
Mutual labels:  gamedev
com.unity.multiplayer.samples.coop
A small-scale cooperative game sample built on the new, Unity networking framework to teach developers about creating a similar multiplayer game.
Stars: ✭ 794 (+3870%)
Mutual labels:  gamedev
agones-event-broadcaster
Broadcast Agones GameServers and Fleets states to the external world
Stars: ✭ 22 (+10%)
Mutual labels:  gamedev
Atlas auto setline
a tool for automatic offline/online unusable slave node in Atlas open source software
Stars: ✭ 47 (+135%)
Mutual labels:  atlas
cl-sdl2-tutorial
SDL2 examples in Common Lisp based on Lazy Foo tutorials.
Stars: ✭ 55 (+175%)
Mutual labels:  gamedev
awesome-playdate
A list of awesome resources for Playdate (https://play.date) game development and the Playdate SDK (https://play.date/dev/)
Stars: ✭ 149 (+645%)
Mutual labels:  gamedev
alpha
alpha - deprecated 2015~2016. unrelated to the new engine! view the new engine here - https://luxeengine.com/
Stars: ✭ 573 (+2765%)
Mutual labels:  gamedev
Deadrop
Deadrop is a small game engine that was made as part of the Afterback project.
Stars: ✭ 17 (-15%)
Mutual labels:  gamedev
const-tweaker
🤪 Tweak constant variables live when running a program
Stars: ✭ 65 (+225%)
Mutual labels:  gamedev
minigdx-game-template
Basic template to create a game using minigdx
Stars: ✭ 16 (-20%)
Mutual labels:  gamedev
gamestudio
2D game engine and editor
Stars: ✭ 207 (+935%)
Mutual labels:  gamedev
framework
The exomia/framework is used for building 2D and 3D games and more inspired by the XNA/Mono framework.
Stars: ✭ 21 (+5%)
Mutual labels:  gamedev
deffx
A collection of useful shader effects made ready to be used with the Defold game engine
Stars: ✭ 33 (+65%)
Mutual labels:  gamedev
polymorph
A fast and frugal entity-component-system library with a focus on code generation and compile time optimisation.
Stars: ✭ 74 (+270%)
Mutual labels:  gamedev
MedievalWar
A simple turn-based strategy game using Phaser 3
Stars: ✭ 22 (+10%)
Mutual labels:  gamedev
BonEngineSharp
A simple and fun SDL-based game engine in C#.
Stars: ✭ 16 (-20%)
Mutual labels:  gamedev
gamedevguide
Game Development & Unreal Engine Programming Guide
Stars: ✭ 314 (+1470%)
Mutual labels:  gamedev
ProceduralTerrain
Polygon is a procedural mesh generator in Unity.
Stars: ✭ 18 (-10%)
Mutual labels:  gamedev
magnum-tips
Collection of useful snippets for https://magnum.graphics
Stars: ✭ 27 (+35%)
Mutual labels:  gamedev

textureatlas

A simple, cross-platform tool and C library for creating and using a texture atlas in your application or game. Distributed under the terms of the MIT license.

What is a Texture Atlas?

A Texture Atlas is a texture (raster image) composed of multiple smaller textures. By loading a single large texture, you can reduce resource load time and improve performance by minimizing the number texture bind calls during rendering. A texture atlas is accompanied by a map file that identifies the coordinates and dimensions of each texture in the atlas.

textureatlas.py

textureatlas.py is a Python-based command line tool that can be used to generate a texture atlas and accompanying map file from one or more images. Images can be grouped together as individual frames of the same texture (for animated sequences, for instance). Each texture has a name that is used to identify the texture in the atlas map file.

Map File

The .map file generated by textureatlas.py is a simple binary file intended to be loaded with libtextureatlas from your C or C++ game/application. The format of the map file is documented in the source code.

Supported Image Formats

textureatlas.py uses the Python Imaging Library to handle image manipulation, loading, and saving and hence supports many commonly used image file formats including PNG, BMP, GIF, JPEG, and TGA.

System Requirements

Usage

usage: textureatlas.py [-h] [-o output-file] [-m mode] [-s size]
                       texture [texture ...]

Packs many smaller images into one larger image, a Texture Atlas. A companion
file (.map), is created that defines where each texture is mapped in the atlas.

positional arguments:
  texture               filename of texture

optional arguments:
  -h, --help            show this help message and exit
  -o output-file        output filename (atlas.png)
  -m mode, --mode mode  output file mode (RGBA)
  -s size, --size size  size of atlas (n x n)

Texture Parameter Format

The format of a texture parameter is as follows:

[<name>=]<frame0.png>
[<name>=]"<frame0.png> <frame1.png>"

The <name> of a texture is used to identify the texture in the texture atlas map file. If you omit the <name> of the texture, the filename of the first frame, without the extension, will be used.

Example 1
textureatlas.py crate=texture1.png texture2.png

This example generate an atlas containing two textures, each of one frame, with names 'crate' and 'texture2', respectively.

You may specify additional frames of a texture (e.g. for animated sequences) by enclosing the filenames of the frames in quotes.

Example 2
textureatlas.py "texture_frame0.png texture_frame1.png" texture2.png

This example generate an atlas containing two textures. The first texture, named 'texture_frame0', contains two frames. The second texture, named 'texture2', contains only a single frame.

Example 3
textureatlas.py apple=picture_of_an_apple.png fire="fire0.png fire1.png"

This example generate an atlas containing two textures. The first texture, named 'apple', contains only a single frame. The second texture, named 'fire', contains two frames.

Using command-line tools, you can easily specify multiple frames for a texture from a directory listing.

Example 4
textureatlas.py fire="`ls sample/fire/*.png | xargs`"

This example list all the .png files in the sample/fire directory as frames for the 'fire' texture.

libtextureatlas

libtextureatlas is a small C library with a simple API for loading and accessing a binary texture atlas map file created by textureatlas.py. It has no dependencies on other libraries and can be easily integrated with your existing project, especially if you are using CMake.

Please note that libtextureatlas will not load the image data of the texture, just the map file. There exist several good libraries for loading images; for loading and decompressing PNG images, you may be interested in LodePNG.

Example Usage

Loading a Texture Atlas Map File

texture_atlas_t *ta;
int result;

result = texture_atlas_load("atlas.map", &ta);
if (result) return 1;

Looking Up a Texture by Name

texture_atlas_texture_t *texture;

texture = texture_atlas_lookup(ta, "blaster");
if (texture == NULL)
{
    free(ta);
    return 1;
}

Stepping Through Texture Frames

texture_atlas_texture_t *texture;
texture_atlas_frame_t *frame;
unsigned int i;

for (i=0; i < texture->num_frames; i++)
{
    frame = texture->frames + i;
    printf("Frame %d is at %d, %d.\n", i, frame->x, frame->y);
}

License

Licensed under the terms of the MIT license:

The MIT License (MIT)

Copyright (c) 2014 Matthew Borgerson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].