8
\$\begingroup\$

I have some questions about the creating graphics for a game.

As an example. I want to create a motorbike. (1pixel = 1centimeter) So my motorbike will have 200 width and 150 height. (200x150) But the libgdx only allows to load sizes with the power of 2?! (2,4,8,16,...)

First I thought about that way. I will create my bike with the size (200x150) and save it as png. Than I will open it again (e.g. with gimp) resize the image to a size which uses values with power of 2 (128x128). I will load that as texture in the programm and set width as 200 and height as 150.

But wouldn't it be a problem? Because I will lose some pixel information when I make the first conversation.?! Isn't it?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Libgdx has an texture packer that will combine your images to a few bigger images (atlases) and help you only draw the part of it you want. \$\endgroup\$
    – Matsemann
    Sep 15, 2012 at 9:17

3 Answers 3

11
\$\begingroup\$

The reason you're limited to power-of-two sizes is due to how video ram works. Note that what you should do is typically make the image the next highest power of two (.e. 512x256), and then just use a portion of that image for your graphics. You'd be setting your UV coordinates to only use a subsection of the image onto whatever triangles you're rendering.

If you're worried about memory usage, you could also use some of that left over space on different objects and UV map those objects to that part of the texture. Making a texture like this is also known as an "atlas".

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Worth mentioning that atlases also optimize in performance, because the less you switch textures, less batches, faster drawing. \$\endgroup\$ Sep 14, 2012 at 17:10
3
\$\begingroup\$

You must use texture coordinates instead of resizing, like draw only part of the whole texture. I don't know how it works in libgdx but it's common to use this approach. Another approach is to use texture atlas, you have in memory e.g 1024x1024 and then when you load your image you load it to atlas rectangle.

\$\endgroup\$
0
\$\begingroup\$

You can convert the size of your image a little bigger or smaller according to the appropriate size. I had used this link - http://www.garyshood.com/imageconvert/ You can use a size that would be completely divisible by 2. For example, if your image size is 200, then 200/2=100;100/2=50;50/2=25, so here 25 is not divisible by 2. Therefore, 200 is not an appropriate size. You can use 1024, 512, 256, 128 and so on.. And then you can use portions of that image in your graphics. The other alternative would be to combine all your textures into the texture atlas easily using the libgdx Texture Packer GUI and then using texture from that atlas.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .