Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Moony Texture Packer - Quick and Simple Texture Atlas  (Read 5072 times)

0 Members and 1 Guest are viewing this topic.

Ricky

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Tejada
    • Email
Moony Texture Packer - Quick and Simple Texture Atlas
« on: October 22, 2015, 08:45:24 am »
Hello everyone, it's been a while. I've been working on a tool for packing textures and sprite batching. Here is the repo: https://github.com/ricanteja/MoonySpriteBatch.

How To Use

The library is made up of just 2 headers (Log.h is a bonus). Those are SpriteBatch.h and TextureAtlas.h. These files know everything about loading texture atlases created by the Texture Packer and how to draw sprites.

Texture Packer

Once built you can drop the Texture Packer tool in any directory you want but it is most useful when usd from the commandline. When you run it without any args by default it will sniff around it's current directory for any images to pack. Texture pack files are named after the folder they were created in and texture pack images begin with ta_[NUMBER][FOLDER], for instance: ta_0myimages.png.

Here are the options you can pass to the tool:

-h : Prints a help message with the list of options
-b : Tells the tool not to produce seperate atlas image files but rather compress the raw color data and pack everything into the .mtpf texture pack file
-f [FOLDER] : Designate a folder you specifically want the tool to work in
-r : Recursivley search through all directories under the starting directory. This can be used together with the -f flag
-d [COUNT]: Produce [COUNT] # of debug textures.
-v : Outputs more messages.

Example

The moony::TextureManager class is in charge of loading your texture atlases you made with the tool. You should only need one instance of this object since it can load multiple texture atlases. You can search for the exact texture you want to assign to your sprite by searching by it's original name.

moony::TextureManager textureman;

textureman.loadFromFile("pack.mtpf");

moony::Sprite sprite(textureman.findSubTexture("happytree.png"));

To draw a sprie you need a moony::RenderManager class. It works fairly similar to SFML's own Drawable class (mostly because it inherits from it). Again you should really only need one instance of this class.

moony::RenderManager renderman;

...

window.clear(sf::Color::Black);

renderman.clear();
renderman.draw(sprite);
renderman.batch();

window.draw(renderman);
window.display();

The project has an additional dependency, Zlib, aside from SFML ofcourse. I'm not really good with CMake just yet but I wanted to share it. Maybe someone can use it, learn from it or someone can tell me what I can change and I can learn too.

Everyone loves pictures. Testing that layers indeed work. I didn't upload with the tons of images because it would have been annoying to see all that stuff spinning and doing stuff. But it works so yay!


Here is a picture of what the debug output of the Texture Packer looks like.
« Last Edit: October 22, 2015, 08:47:57 am by Ricky »
Wilt thou yet say before him that slayeth thee, I am God? but thou shalt be a man, and no God, in the hand of him that slayeth thee.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: Moony Texture Packer - Quick and Simple Texture Atlas
« Reply #1 on: October 22, 2015, 10:04:52 am »
Nice, have to try that later. :)

Resethel

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: Moony Texture Packer - Quick and Simple Texture Atlas
« Reply #2 on: October 22, 2015, 06:06:17 pm »
I really like your tool ^^

Ricky

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Tejada
    • Email
Re: Moony Texture Packer - Quick and Simple Texture Atlas
« Reply #3 on: October 22, 2015, 08:54:08 pm »
I didn't really have time to write this last night but I wanted to write something a bit more technical about how my tool is different.

I use SFML to load textures and then using my own algorithm to pack them into a larger single sf::Texture. The algorithm is optimized for textures of similar height but can still be improved. Then the texture is copied to an sf::Image and if the -b flag is on the Texture Packer will grab the raw color data and compress it with zlib and write it to the .mtpf file. If the -b flag is not set the tool will output a ta_*.png file and link to it in the .mtpf file. The compressed data is usually is half the size of it's ta_*.png counterpart.

The TextureManager will load the .mtpf files you made with the tool and you can access your original files by name. The function moony::TextureManager::findSubTexture returns a moony::SubTexture object which contains a pointer to the texture where the pixels live and a sf::IntRect describing what portion of the texture is our actual sprite. The moony::SubTexture object can be used with sf::Sprite by setting the texture and setting the TextureSubRect and will work just fine.

I plan on making more in depth examples but for now it is time to work on something else. Maybe later today I'll provide some windows binaries.
Wilt thou yet say before him that slayeth thee, I am God? but thou shalt be a man, and no God, in the hand of him that slayeth thee.

 

anything