Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Programmer16

Editing a texture's data

This topic is 5146 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''m trying test something, and it requires me to edit the textures (using DirectX9). What I''m trying to do is edit the texture each frame and copy all of the different tiles into one texture, then using a single quad to render the map. I don''t know if this is a bad idea or not, but I''d still like to know how to edit a texture''s data. I know that you can use the LockRect() to get the data, or you can use the GetSurfaceLevel(), but I don''t know what the first one does, and I tried the second, but it didn''t work. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
This lesson locks a texture and plays with its bits:
http://www.drunkenhyena.com/docs/d3d_tutorial.phtml#DHComputedAlpha

It''s DX8, but that part is virtually the same.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
I''m trying to do exact the same thing. I tried to edit my textures the same way as that tutorial (tried to change colours of 24-bit image by putting three unsigned char values per every pixel), but nothing seems to change. I''m using dynamic vertex buffer and it''s POOL is D3DPOOL_DEFAULT.

And how about dynamic textures. Aren''t they the fastest way to make textures that can be edited every frame? I tried to use dynamic textures but couldn''t get them work correctly, images were messy. Does using dynamic textures require some other changes than altering the parameters of my D3DXCreateTextureFromFileEx? How can I find out if my hardware even supports dynamic textures or not? I know I should check if there''s D3DCAPS2_DYNAMICTEXTURES in Caps2-member of D3DCAPS9 Structure, but I don''t know how this could be done.

Or is there some other (and better) way to make 2d-map that can be edited during game (I want destructible walls)?



Share this post


Link to post
Share on other sites
You should check what format your texture has. There are very few 24-bit formats and they are poorly supported.

Dynamic textures are good, but not all cards support them. They should be created write-only and dynamic in the default pool. Lock them with the DISCARD flag.

This tutorial briefly covers checking CAPS bits.



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
You were right about that format. Even though I saved it as 24-bit image, and Paint Shop Pro says that it is, it is equal to D3DFMT_X8R8G8B8-flag (32-bit) as DirectX-texture. I wonder why.

But that was not the reason for it not working. The reason was that my MipLevels-parameter was 0 instead of 1. I didn''t even know what those miplevels meant, but now I found out. That problem with dynamic textures is gone too, they seem to work fine.

Thanks alot!

Share this post


Link to post
Share on other sites

  • 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!