I was wondering if anyone knew a good algorithm to generate power-of-two textures from a set of smaller tiles/sprites?
Problem: A number of tiles/sprites of different dimensions should be placed in one or more images of power-of-two dimensions, wasting as little space as possible.
If you can do the work offline, then nVidia’s tools might be worth a look: http://developer.nvidia.com/object/texture_atlas_tools.html
Yes, the generation of tilesets should be done by the level-editor. I’ll take a look at your link, thanks.
If you are doing this process offline, no problem. But if you are doing this at runtime (I think thats the best solution IMO), then your going to have to deal with texture coordinate shifting. Basically, find what objects are using this texture, hold them in a list somewhere, shift the texture, then bring the texture coordinates of those objects to the range at which your image is now in.
I might have a go at it myself
DP
I’m not quite sure I understand what you’re talking about?
As I see it all I need to know when rendering a sprite is the texture that contains it, it’s coordinates inside the texture and its dimensions. (+ of course “hotspot” x and y)?
Maybe we’re talking about the same thing?
I thought you are using OpenGL because you were referring to POT textures, my bad.
DP
I might be using OpenGL in the future, atm I’m just using Java2d and drawImage()
But still it would be preferrable to pack small tiles/sprites into power-of-two sized images since Java2d hardware acceleration probably just pads non power-of-two images - probably wasting huge amounts of VRAM.
It seems like a bin-packing problem which is proven to be NP-complete so I don’t expect an optimal solution to this
Yes it is NP-complete. You can probably come up with some reasonably good heuristic solution by experimenting a little with cut out paper rectangles
Sorry for offtopic. I’m new to java 2d and don’t quite get what are you talking about so please let me see if I understood… if you use images with size that has form of x^2 where x is natural number, drawing is better? Can someone please explain in more detail or give a link. We’re talking about size as in width and height or byte usage for storing?
???
Thank you.
Java2D hardware-accelerates BufferedImages that are compatible with the screen.
It caches the image in a texture in video RAM - and on many graphics cards textures need to have dimensions that are whole powers of two, (2^x, not x^2). So I can only assume that images that don’t have power of two dimensions are padded when cached in VRAM. This could waste quite a bit of VRAM…