50 * 256x256 bitmaps into one huge bitmap. But how huge?
I got 50 bitmaps, each being 256x256 large.
How do I calculate how large a bitmap I need to allocate to be able to fit all these into one huge bitmap? Simple math, but I haven't figured it out so far. I remember studying this in school, but it seems so long ago..
Thanks in advance!
Quote:Original post by Sneftel
...
12800x256?
That's hardly a calculation, but okay. My question was vague, sorry.
I'll rephrase:
---------------------------------
4 bitmaps, each 256x256 fit into a larger bitmap of 512x512. But how do I calculate this, if I know how many bitmaps I have, and their size? That's for square bitmaps, power of two.
If you have n=a*b bitmaps, and each one has size w×h, you can fit them into a (w*a)×(h*b) bitmap. If n happens to be a square number, you can set a=b=sqrt(n). Is... any of this helping?
Quote:Original post by SymLinked
I got 50 bitmaps, each being 256x256 large.
How do I calculate how large a bitmap I need to allocate to be able to fit all these into one huge bitmap? Simple math, but I haven't figured it out so far. I remember studying this in school, but it seems so long ago..
5x10 * bitmap.
or 8x8 if you need perfect square.
or an array of 50 bitmaps.
I think he wants the (approx) square root of the number of bitmaps... probably rounded up..
50^0.5 = 7.07106781
rounded up, 8x8 tiles, so 8*256 x 8*256 = 2048x2048
50^0.5 = 7.07106781
rounded up, 8x8 tiles, so 8*256 x 8*256 = 2048x2048
Hmm, and if you require the final size to be a power of two...
Take the square root of the number of tiles in the texure
Take the base-2 logarithm of that value
Round up to the next integer
the number of tiles across and down should then each be 2^result
Ex:
You have 99 tiles
99^0.5 = 9.94987437
log2(9.94987437) = ln(9.94987437) / ln(2) = 3.31467831
ceiling(3.31467831) = 4
2^4 = 16
...so 16x16 tiles
16*256 x 16*256 = 4096x4096
Take the square root of the number of tiles in the texure
Take the base-2 logarithm of that value
Round up to the next integer
the number of tiles across and down should then each be 2^result
Ex:
You have 99 tiles
99^0.5 = 9.94987437
log2(9.94987437) = ln(9.94987437) / ln(2) = 3.31467831
ceiling(3.31467831) = 4
2^4 = 16
...so 16x16 tiles
16*256 x 16*256 = 4096x4096
To have a power of two texture you need a power of two number of 256x256 tiles. The total number of tiles required is 2ceil(log2(n)). In the case of 50 tiles the formula gives 2ceil(log2(50)) = 26 = 64
The possible ways to form that texture are 256x16384(1x64 tiles), 512x8192(2x32), 1024x4096(4x16), 2048x2048(8x8). If you want to minimize the difference between the width and the height you can use the following formula:
m = ceil(log2(n))
width = 2ceil(m/2)
height = 2floor(m/2)
The possible ways to form that texture are 256x16384(1x64 tiles), 512x8192(2x32), 1024x4096(4x16), 2048x2048(8x8). If you want to minimize the difference between the width and the height you can use the following formula:
m = ceil(log2(n))
width = 2ceil(m/2)
height = 2floor(m/2)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement