Editing a texture's data

Started by
3 comments, last by Programmer16 19 years, 10 months ago
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!
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
Stay Casual,KenDrunken Hyena
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)?



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
Stay Casual,KenDrunken Hyena
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!

This topic is closed to new replies.

Advertisement