Jump to content
  • Advertisement
Sign in to follow this  
jesperhw

Direct3D9: How to copy from a Surface to a Texture

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

Hi all.

Just a general question: I want to copy 2D tile frames from a sprite sheet (loaded as a Direct3D9 Surface - or possibly a Direct3D9 Texture, if that helps solving my problem) to a game world map that has to be loaded as a Texture, because it needs to be scaled later.
How can I do that? I know that copying from one Surface to another can be done using StretchRect(), but how can I copy from one Texture to another? I am using Visual C++ and DirectX 9

Thanx

Share this post


Link to post
Share on other sites
Advertisement
If you use GetSurfaceLevel(0, *pointer to any surface object) on a texture you can obtain it's surface, on which you can perform StretchRect() and other operations. Don't forget to release the surface you obtained that way after your done manipulating it, though.

Share this post


Link to post
Share on other sites
StretchRect has various restrictions as documented in the SDK and I would generally not recommend it's use for this case. tex->GetSurfaceLevel is good though, and it's the right place to begin (but don't forget to Release the acquired surface afterwards or you'll have a resource leak!)

I'd say use D3DXLoadSurfaceFromSurface instead - it might not take the fastest path (and I hope that this isn't something you'd propose doing every frame) but it will work in all scenarios.

Share this post


Link to post
Share on other sites
If you end up using GetSurfaceLevel() to get the surface of a texture I ended up using UpdateSurface() but it really depends on what type of memory pool your using for your textures and surfaces.. Thats where the restrictions come in.

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!