handling square textures

Started by
1 comment, last by Luke Philpot 19 years, 7 months ago
Hi, I've recently started writing a GUI using Direct3D rather than DirectDraw. I've heard that it's best to use only square textures using square numbers, i.e 4x4 32x32 128x128, etc. This is causing me a lot of problems when I want to draw non square images to the screen. I've been loading the images which aren't square into a square texture with a colour key value so that when I render the texture to the back buffer the images appear correctly. The problems I'm having a to do with managing it all. I end up having loads of overlapped textured quads when I'm doing things like rendering the parts of a window frame, and managing all this is becoming a real headache. Especially when I need to place things on the screen related to the image size and not the size of the texture it's contained in. Here's an example: Say I've got a 20x10 PNG file that I want to repeat along the screen. I'd load it into a 32x32 texture and render it onto a 32x32 quad, with transparency wherever the image isn't. Looks fine. Then the next quad would overlap the last and so on. Has anyone got any experience with this that they can share? I'd really appreciate it. Many thanks, Daniel
Advertisement
Modern video cards support non power of two textures, so you could use that. However that restricts use of your GUI to people who have the requisite video card. Another solution is to upsize all image you load to the nearest power of two dimensions. Then when drawing a textured quad using that image make the quad the same size as the original image and use nearest-neighbor texture filtering. This may not give you a pixel perfect repoduction of the image you loaded in though.
Try putting all you GUI assets on one (or two) big 256x256 textures. Then when drawing your widgets, you can just feed in the texture coordinates that widget takes up on the texture... if that makes sense (probably doesn't). You'll also save a bit of texture memory and some state changes :)

This topic is closed to new replies.

Advertisement