Direct3D 9 transparent texture scaling problem

Started by
1 comment, last by Krohm 12 years, 2 months ago
I'm working on a 2D rendering engine that uses textured quads. Basically, I create a texture, load the image from a file with ARGB data (such as .png), and then draw 2 triangles using the texture coordinates to get the image on the screen. This works great when I render the image pixel-for-pixel. The problem comes when I scale the image.

I'm using linear scaling (device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR)), and what appears to be happening is the the fully transparent pixels (alpha 0) are having their actual color values blended with neighboring semi-transparent pixels. As an example, I had a red letter 'T' in a 32x32 image. The T was solid (alpha 1.0) and a single outline of pixels around it were the same red, but alpha 0.8. The transparent pixels were alpha 0 and color black. What happens is, when I render on a full white background (device->Clear() using white), I get a black halo around the edges of the T. If I change the fully transparent pixels to be alpha 0 color white, it looks as expected, but if I then render on a fully black background, there is a white halo around the image.

Now, this seems understandable as it is doing a simple interpolation of the data. However, I noticed that I do not have this problem when scaling with Photoshop or when scaling an image in a C# form using Graphics.DrawImage with bilinear scaling.

Is there any way to make DirectX perform this smarter scaling? I've tried every combiniation I could think of in device->SetRenderState() with no luck.
Advertisement
I would suggest reading this.
I also suggest looking at Green's method, it makes magnification quite vectorish in quality, so much they call them "vector textures" or "contour textures". I'm not 100% sold on the terminology but the technique is really good.
For text, it's basically your first and possibly last step to scalable graphics.

Previously "Krohm"

This topic is closed to new replies.

Advertisement