Jump to content
  • Advertisement
Sign in to follow this  
jaredf55

Texture transform and color preservation

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a texture that I am trying to shrink to fit the area it is drawn to. This is a 2D texture being drawn to a sprite. When the texture is shrunk significantly, the colors fade. I'm trying to figure out how to prevent this. I've read a few other articles that imply the faded colors could be prevented by changing the SamplerState for MagFilter and MinFilter. So, immediately before the Draw method, I call SetSamplerState for both the MagFilter and MinFilter and set them to Point. But when I call the Draw method of the sprite, the texture still becomes gray instead of staying white. The Texture is grayscale, but really only uses white and black. And black is transparent. I'm doing this in C# and using slimdx, though any directX ideas would be helpful, and I can figure out what SlimDX Calls are necessary. The actual code is as follows: float scaleFactor = (float)destRect.Width / sourceRect.Width; _sprite.Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point); _sprite.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point); _sprite.Transform *= Matrix.AffineTransformation2D(scaleFactor, new Vector2(0, 0), 0, new Vector2(destRect.X, destRect.Y)); _sprite.Draw(overlayDisplayTexture, new Rectangle(0, 0, sourceRect.Width, sourceRect.Height), new Color4(1.0f, 1.0f, 1.0f, 1.0f)); I appreciate your ideas.

Share this post


Link to post
Share on other sites
Advertisement
I don't know about SlimDX, but in C++ / DirectX, you need to call ID3DXSprite::Begin() which will set all device state for sprite rendering, then you can call SetSamplerState, etc, then Draw(). It could be that this is the same here?

Share this post


Link to post
Share on other sites
I appreciate the reply. And should have clarified, Sprite.Draw and End are being called before and after the posted code, plus the Device.BeginScene and EndScene functions are wraped around the sprite calls.

Share this post


Link to post
Share on other sites
Oddly enough, this issue resolved itself. Not sure what happened or why, since the code hasn't changed in a way that I would think would cause this problem to stop.

Share this post


Link to post
Share on other sites
Ok, so I was mistaken in that it was fixed, becuase it really wasn't. The graphics was changed from using DirectX to GDI. After changing it back, i discovered that it hadn't fixed itself. So, after some guess and check, I learned that I needed to change the code from:
_sprite.Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point);
_sprite.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);

to just:
_sprite.Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.None);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!