Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
1  
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. –  Matsemann Sep 15 '12 at 9:17
add comment

3 Answers

up vote 10 down vote accepted

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".

share|improve this answer
4  
Worth mentioning that atlases also optimize in performance, because the less you switch textures, less batches, faster drawing. –  Gustavo Maciel Sep 14 '12 at 17:10
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.