Sunday, April 9, 2017

opengl - Understanding how to create/use textures for games when limited by power of two sizes


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?



Answer



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


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...