Sign in to follow this  

Resizing a texture?

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

Let's say I have a texture that is 256x256 and I want to make the texture 128x128. I'm not talking about just rendering the texture to the screen smaller, I want the actual texture to be smaller so that when I LockRect and access the pixels, they will be the pixels of the smaller image. What would be the best way to do this? Edit: oh, I'm using C# right now, but I don't really need source code, just a general explaination of the steps and I can probably figure it out.

Share this post


Link to post
Share on other sites
I admittedly don't know much about managed DirectX, but since no one else has yet said anything, after taking a quick look through the docs that came with DX9 2004 Summer Update, I'd suggest looking at Microsoft.DirectX.Direct3D.SurfaceLoader.FromSurface(). I suppose the typical way would be to create a second texture that is smaller than the original, then use FromSurface() to copy data from the primary surface of the old texture to the primary surface of the new texture. After that, get rid of the old texture and use the new one in it's place.

As far as I know, you can't actually simply resize a texture itself. You have to create a new one, copy the data, and get rid of the old one.

At what point in your program and for what reason precisely do you need to do this? There may be a better way to do this, depending on when/why you're downsizing the texture.

Share this post


Link to post
Share on other sites
Well, I would like the texture to be resized with a bilinear filter and since DirectX has no problem doing that when rendering textures, it seems there should be a way to resize a texture like that. I looked at SurfaceLoader.FromSurface() but I think that just copies the rectangle pixel for pixel and doesn't resize.

I just noticed that I could use RenderToSurface and then render the scaled texture as a sprite to the surface... I'll try that now but it seems like there should be a simpler way.

Share this post


Link to post
Share on other sites
Actually, you can do bilinear filtering when loading a file, or when copying a surface. One of the parameters in the longer version of various FromFile or FromeSurface functions is a filter parameter. You'd want to check out the filter enumeration, but Linear looks to be like what you want.

[edit]
TextureLoader.FromFile() function
Filter enumeration
[/edit]

Share this post


Link to post
Share on other sites

This topic is 4841 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.

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