Fanning Software Consulting

Images as Texture Maps

QUESTION: I am tring to add an image as a texture map to a rectangular polygon, But no matter what I do, the image seems to be warped or interpolated incorrectly. At least it appears distorted on the polygon. Am I doing something wrong?

ANSWER: The answer to this question was offered in a February 25, 2005 IDL newsgroup article by Karl Shultz.

This is probably caused by your texture image not having dimensions that are a power of 2. OpenGL has a restriction where texture maps have to have dimensions that are a power of 2. If you use a texture map that does not meet this requirement, IDL resamples the image upwards to the next power of 2 dimensions. This resampling step is probably introducing the aliasing artifacts you see on your image.

The way around this is to place your texture data into a larger image that has dimensions the next power of 2 higher than your texture data, leaving unused areas in the image. Then set your texture coordinates such that you use only the defined parts of the image.

For example, if your texture data is 500x750, make an image array that is 512x1024 and use it to create your IDLgrImage. Fill the image array so that your texture data fills up the [0:499, 0:749] subset of the array. Use this image as the texture map and set the texture coords corresponding to the rectangle to this:

   [ [0,0], [500./512, 0], [500./512, 750./1024], [0, 750./1024] ]

Note that IDLgrSurface does this sort of thing for you automatically, so I suppose another work-around is to use a surface object instead of a polygon object.

Google
 
Web Coyote's Guide to IDL Programming