Jump to content
  • Advertisement
Sign in to follow this  

reading raw texture data

This topic is 5047 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. I have a texture created as a render target and using D3DPOOL_DEFAULT. I want to be able to read the information about each pixel in this texture. How can I do this? I have experimented a little but am rather confused about surfaces/textures and when and how you create each. From what I can gather...get the surface of the texture, copy that to a surface of a texture in system memory, call LockRect on a system mem texture then read from that?
Something like...

            CComPtr<IDirect3DTexture9> sysmemTexture = NULL;
            CComPtr<IDirect3DSurface9> sysmemTextureSurface = NULL;
            CComPtr<IDirect3DSurface9> texsurface = NULL;
            // create the new texture
            hr = m_data.m_pDev->CreateTexture(1024,
            // get the surface rep of the texture
            m_data.m_pTexture->GetSurfaceLevel(0, &texsurface);
            // get the surface rep of the sys mem texture
            sysmemTexture->GetSurfaceLevel(0, &sysmemTextureSurface);
            // move the texture surface data to system memory
            m_data.m_pDev->GetRenderTargetData(texsurface.p, sysmemTextureSurface.p);
            // lock the texture data
            D3DLOCKED_RECT *pRect = new D3DLOCKED_RECT;
            sysmemTexture->LockRect(0, pRect, NULL, D3DLOCK_READONLY);
            // do stuff here
            delete pRect;

However when I reach the line m_data.m_pTexture->GetSurfaceLevel(0, &texsurface); it not only changes the value of the pointer in texsurface but also sets sysmemTexture to NULL :S I am rather confused and really require some help. Do I still have to allocate memory when using CComPtr or will it do it for me? If I have to do it myself, how do I go about creating my won IDirect3DTexture9 / IDirect3DSurface9? (Is what I have done above ok in theory?) Thanks very much for any help, BBB.

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!