texture sizes, handling and design

Started by
2 comments, last by sprinter_trueno 17 years, 1 month ago
Hello, I have the problem that texturing confuses me more and more. To make sure that my game is not HW dependent, it seems to be to use only textures with POT dimensions and on top square. Well, no problem but how to handle the obvious fact that not all my rectangles do not have a square form but are most of the time "just" rectangles with not even one side matching the dimensions of the texture/surface ? I mean it would be possible to use texture coordinates but for a perfect texel pixel matching one should use 0,0 and 1,1 for U and V as I understand. How is this to be handled ? Any thoughts ?
Advertisement
You could save all your images as power of 2, leaving space around the edges empty. This wastes hard drive space, though.

Although I'm not sure what the value of keeping textures square and power-of-two is. Don't practically all modern video cards support non-square and non-power-of-two textures?
NextWar: The Quest for Earth available now for Windows Phone 7.
You can safely ignore square textures. There might be some ancient DX7 card that requires it, but I imagine you might run into 5 people on the planet still using such a card.

I'd recommend pow2 sizes though. While most cards CAN deal with non-pow2 textures, it's still often nonpow2conditional, which has many restrictions. Cards that can do non-pow2 without restrictions often have sever performance hits if you use it.

You can get perfect texel to pixel mapping without using the full 0..1 range.

You can tell D3DX to use filter "none" when loading a non-pow2 texture. This will create a pow2 texture, but only fill in the needed upper left corner of it. You can use the "info" structure from the load call to determine how much of the texture was used, and use GetSurfaceLevelDesc to find the dimensions of the texture created. With those two needs bits of information, you can create your UVs.
Thanks alot. That is what I needed to hear. So if my bitmaps are located in the upper left corner of the surface, then of course I need to cacluate U and V as you said. I use the following code to do so.

/* Valid texture */if ( strTexture.pclsTex ){	/* Calculate LEFT UPPER */	strRect.strVert0.fU = (float)iX / (float)strTexture.strSizeSurf.cx;	strRect.strVert0.fV = (float)iY / (float)strTexture.strSizeSurf.cy;	/* Calculate RIGHT UPPER */	strRect.strVert1.fU = (float)(iX + dwWidth) / (float)strTexture.strSizeSurf.cx;	strRect.strVert1.fV = strRect.strVert0.fV;	/* Calculate LEFT LOWER */	strRect.strVert2.fU = strRect.strVert0.fU;	strRect.strVert2.fV = (float)(iY + dwHeight) / (float)strTexture.strSizeSurf.cy;	/* Calculate RIGHT LOWER */	strRect.strVert3.fU = strRect.strVert1.fU;	strRect.strVert3.fV = strRect.strVert2.fV;}


iX and iY are the left upper pixel to be used from the bitmap.
dwWidth and dwHeight the number of pixel to use incl. the upper left.

Could you confirm that I am doing it right ?

Thanks for the help.

This topic is closed to new replies.

Advertisement