Jump to content
  • Advertisement
Sign in to follow this  
AndreTheGiant

scaling down a texture causes it to fade away (transparency increases?)

This topic is 1150 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

Ok so I'm reviving an old project that uses old school managed DirectX. I know its deprecated but I'm really hoping I can get a straight answer without everyone focusing on the wrong thing smile.png

 

I want to draw some stuff (images/textures) onto a larger texture, and then show that larger texture on the screen. Then I want to shrink the larger texture (scale it down) slowly over time. So far everything seems to work fine until I start shrinking the texture. The transparency seems to shrink along with the scale, and the whole thing slowly fades away as it gets smaller! I've been scratching my head for hours and I'm sure its one of those easy answers to the right person. Please let me know what could be happening!

 

Ive stripped my code down to a pretty simple example below. I even was able to remove all the drawing-to-texture code. It currently just draws a 524x524 square of Orange. When it scales down, it dissapears !

Not shown in the code below, but I have the scaleFactor variable slowly transition from 1.0f to 0.0f. The orange square slowly fades to black (the background is black so I believe the opacity of the orange square is also going from 1 to 0). The square actually fades away to nothing long before its size is reduced to zero. I'd guess that its completely faded away by the time its scaled to about 50% size.

mapSprite = new Sprite(GraphicsMain.m_device);
mapTexture = new Texture(GraphicsMain.m_device, 524, 524, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);  //Format.A8R8G8B8
            

            Surface surface = mapTexture.GetSurfaceLevel(0);
            Surface buffer = GraphicsMain.m_device.GetRenderTarget(0);

            GraphicsMain.m_device.SetRenderTarget(0, surface);
            GraphicsMain.m_device.Clear(ClearFlags.Target, System.Drawing.Color.Orange, 1.0f, 0);
            
            // draw some stuff here..
            // Done rendering to texture

            
            GraphicsMain.m_device.SetRenderTarget(0, buffer);


// now draw it to screen
mapSprite.Begin(Microsoft.DirectX.Direct3D.SpriteFlags.AlphaBlend);
            mapSprite.Transform = Matrix.AffineTransformation2D(scaleFactor, Vector2.Empty, 0, new Vector2((float)50, (float)50));
            mapSprite.Draw(mapTexture, Vector3.Empty, Vector3.Empty, Color.White.ToArgb());
            mapSprite.End();  
Edited by AndreTheGiant

Share this post


Link to post
Share on other sites
Advertisement

You are not filling the mip levels of the texture. The unfilled levels represent transparent black (0).

Share this post


Link to post
Share on other sites

Thanks guys! You were exactly right. I knew it was something simple. You saved me probably a few more house of frustration!

 

As a side note, I now realize that I actually do need to do create mipmaps, so I gotta find a tutorial on how to create mipmaps given a Bitmap image...

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!