Jump to content
  • Advertisement
Sign in to follow this  
Lutz

Reading ARGB values from textures in MDX/C#

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

Hey, I'm trying to get the contents of a certain texture level as an array of ARGB colors from a Texture in Managed DirectX 9 and C#. The code for loading the texture is
Texture texture = TextureLoader.FromFile(
                    device,
                    filePath,
                    0, 0, 0,
                    Usage.None,
                    Format.Unknown,
                    Pool.Default,
                    Filter.Linear, Filter.Linear,
                    0))
Note that I use Format.Unknown (so the source format is taken which is DDS) and that I'm using the default pool because I *think* this has higher performance. I tried to lock a rectangle by
Color32[] colors = (Color32[])texture.LockRectangle(typeof(Color32), nLevel, LockFlags.ReadOnly, out pitch, width * height);
which throws an exception if I use the default pool (works with managed). If I change the pool to managed, I still have the problem that the function does not return ARGB colors but something weird. If I change Format to Format.A8R8G8B8, this works, but my texture is no longer compressed, which is very bad. Since I'm quite new to DX, I don't know what's the "usual" way to read back texture values. All I actually want to do is to compute the average color of a texture. Any easy way to do that? Any good books on this topics? Lutz

Share this post


Link to post
Share on other sites
Advertisement
Default resource can not be locked because use only video memory.
Compressed resource can not be read as usual because is not standard value but a special one to compress data. Probably there is an algorithm to read.
To get texture information use TextureLoader.ImageInformationFromFile to see what type of texture format you are using. When you pass A8R8G8B8 you are converting it, not using the image format.


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!