Jump to content
  • Advertisement
Sign in to follow this  
nickwinters

Reading Pixel Data off Surfaces in MDX

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

To render to a texture, I use device.BeginScene(surface). Do I need to set some sufrace properties before that? And then how do I read the pixel data from it after the render? Thanks. -Nick

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by nickwinters
To render to a texture, I use device.BeginScene(surface).


Wow, does that work? I have never seen that before and its not documented in the release I am using.

Generally there are two ways or rendering to a surface. 1. Using the RenderToSurface helper class. 2. Setting a surface to be the render target by calling SetRenderTarget().

Quote:

Do I need to set some sufrace properties before that?


The surfcae does need to fulfil some special requirements to be used as a render target see Device.SetRenderTarget for details.

Quote:

And then how do I read the pixel data from it after the render?


Lock it using LockRect() and read the data. Sample it in your pixel shader. Turn it into a bitmap and get GetPixel. Depends on what you are trying to do with it. No matter what you do reading back a render target can be slow, even horribly, terribly, incredably slow.

Share this post


Link to post
Share on other sites
Turns out the BeginScene function is a member of the RenderToTexture helper class. I'll take a look at SetRenderTarget.

In terms of reading the individual pixels on the texture, I've done this in C++, but other than locking and unlocking, I can't find the same methods in C#. Do you have any sample code for this?

Thanks.

-Nick

Share this post


Link to post
Share on other sites
Quote:
Original post by nickwinters
In terms of reading the individual pixels on the texture, I've done this in C++, but other than locking and unlocking, I can't find the same methods in C#. Do you have any sample code for this?


Sorry, no sample code, but it ought to be pritty much the same as in c++. Use LockRect() on the surface to aquire either a GraphicsStream or an array. Depeinding on the type of surface you should be able to read individulal piexls by calling read on the stream and specifing an equivently sized type. if you are using A8R8G8B8 for example reading with typeof(int) should return a value that you can easily convert into a ColorValue. Using the Width/Height of the surface's Description you should be able to locate a specific pixel. You may have to account for padding depending on your hardware, but I don't know the exact details of that.

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!