Sign in to follow this  

Direct3D 9 transparent texture scaling problem

Recommended Posts

bbyam    115
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.

Share this post

Link to post
Share on other sites
Krohm    5030
I also suggest looking at [url=""]Green's method[/url], it makes magnification quite [i]vectorish [/i]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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this