PDA

View Full Version : Image size



Tyan
08-25-2012, 06:55 PM
Hey all,
So for a 2d game is it ok to us any image size you want. I ask because I am making my basic soldier about 52x52 pixels, but would it be more efficient to stick with powers of 2, 64x64 for example. I am generally a 3d artist and for that powers of 2 are more efficient for the real time aspect. Thanks for your time.

Cheers,
Tyan

Judas
08-27-2012, 01:26 AM
Both 2D and 3D is drawn the same way today (2D is drawn like billboards in 3D by the GPU), so the rules you know from 3D also apply to 2D. Using power-of-two textures is faster.

However the overhead is generally less important for 2D because the total face count for the scene is very low in comparison (each image box is drawn as two triangles) and any overdraw is easier controlled. So I'd say in general you shouldn't care if your soldier is power-of-two or not.

The best way to improve performance in 2D is to pack all your images into one texture. There is a texture packer tool included with ClanLib that can do this, if I remember correctly. The basic idea is to create a 256x256 texture with all your images, which reduces texture changes and also gives you a power-of-two texture in the end. It is mainly the avoidance of texture changes that improves the performance. Bit like using only a few materials in a 3D mesh improves performance there.

sphair
08-27-2012, 10:15 AM
Yes, ClanLib provides a texture packer tool that handles this.

What it does is that it reads a resources.xml file, finds all images in it, and packs them into a specific texture size which you choose. Normally you'd start with small texture size, and increase the size if the images doesn't fit. Going up to 2048x2048 isn't a problem - that texture size is very safe these days. When its done packing, it saves out the generated texture(s) AND saves a modified resource file for you with replaced references, so the game won't need to be changed at all.

So its easy to start out without using this tool, and just bake the final texture when you approach a release. Just make sure you use ClanLib resource files, though.

http://clanlib.org/w/images/thumb/b/bd/Example_texturepacker.png/800px-Example_texturepacker.png

Tyan
08-28-2012, 04:32 PM
Thanks for the replies, but were is this image packer? I went through my install directory and cant find it.

Thanks,
Tyan

rombust
08-28-2012, 08:02 PM
ClanLib-2.3.6/Utilities/TexturePacker

Tyan
08-29-2012, 06:27 PM
I wish it was that easy but that directory does not exist. Do I need to compile the source code to get that or a separate download? I'm sorry I seem like I don't have a clue as to what I am doing but I really am having a problem finding this.

rombust
08-30-2012, 05:55 AM
It's there... In http://clanlib.org/wiki/Download http://clanlib.org/download/releases-2.0/ClanLib-2.3.6.zip (Windows) or http://clanlib.org/download/releases-2.0/ClanLib-2.3.6.tgz (Linux)

luwak
11-06-2012, 09:07 AM
In case a beginner (more beginner than me) read this thread and decide to keep non-power of 2 images sizes because performances is usually not an issue in 2D, you should still keep in mind that you should not use odd sizes, do use only even sizes. For example 52x52 pixels are fine, but 53x53 pixels are not. If your computer displays odd sizes correctly, a lot of other computer won't.

rombust
11-08-2012, 04:51 PM
For example 52x52 pixels are fine, but 53x53 pixels are not. If your computer displays odd sizes correctly, a lot of other computer won't.


Where did you read this? It sounds more like a bug in an SDK, than the driver.

Non power of 2 textures have been supported since OpenGL 2.0 was released in 2004

luwak
11-10-2012, 11:59 AM
Where did you read this? It sounds more like a bug in an SDK, than the driver.

Non power of 2 textures have been supported since OpenGL 2.0 was released in 2004

You have not understood my message.

I'm not talking about "non power of 2" sizes, but "ODD" sizes.

Please keep in mind that there are a lot of integers that are even but not powers of 2.


http://en.wiktionary.org/wiki/odd:

9. (not comparable) Not divisible by two.

http://en.wiktionary.org/wiki/even:

4. (not comparable, of an integer) Divisible by two.

Judas
11-10-2012, 10:31 PM
Have you experienced that ClanLib has problems with odd sized images? That sounds very strange.

The only situation I can think of where this could trigger a bug is if there is some kind of word or dword alignment requirement on upload is not being followed and odd sized images then is missing some padding bytes.

rombust
11-10-2012, 10:33 PM
Heh, sorry for confusing you :)

"Where did you read this? It sounds more like a bug in an SDK, than the driver."
is relating to "For example 52x52 pixels are fine, but 53x53 pixels are not. If your computer displays odd sizes correctly, a lot of other computer won't."
i.e. The is no technical difference between 52x52 pixels and 53x53 pixels, therefore the bug is in the source SDK or the driver.

And...

"Non power of 2 textures have been supported since OpenGL 2.0 was released in 2004"
is relating to "decide to keep non-power of 2 images sizes because performances is usually not an issue in 2D"
i.e. I mean performance should be identical on modern gpu's

5 years ago, things may have been different.

I could be wrong of course