• Advertisement
Sign in to follow this  

Screenshot to texture

This topic is 1800 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 need to take a screenshot to a texture to make some transition effects.

 

Right now this is what I have

 

public static Texture TakeSnapshot(Device device)
{
    Texture texture = null;
 
    using (Surface renderSurface = device.GetRenderTarget(0))
    {
        using (Surface offscreenSurface = Surface.CreateOffscreenPlain(device, renderSurface.Description.Width, renderSurface.Description.Height, renderSurface.Description.Format, Pool.SystemMemory))
        {
            device.GetRenderTargetData(renderSurface, offscreenSurface);
 
            texture = offscreenSurface.GetContainer<Texture>();
        }
    }
 
    return texture;
}

Share this post


Link to post
Share on other sites
Advertisement
I also tried this
 
 
public static Texture TakeSnapshot(Device device)
{
    Texture texture = null;
 
    using (Surface renderSurface = device.GetRenderTarget(0))
    {
        using (Surface offscreenSurface = Surface.CreateOffscreenPlain(device, renderSurface.Description.Width, renderSurface.Description.Height, renderSurface.Description.Format, Pool.SystemMemory))
        {
            texture = new Texture(device, renderSurface.Description.Width, renderSurface.Description.Height, 1, 0, renderSurface.Description.Format, Pool.Default);
            Surface surface = texture.GetSurfaceLevel(0);
 
            device.GetRenderTargetData(renderSurface, offscreenSurface);
            device.StretchRectangle(offscreenSurface, Rectangle.Empty, surface, Rectangle.Empty, TextureFilter.None);
        }
    }
 
    return texture;
}
But I get the error "[5220] Direct3D9: (ERROR) :D3DPOOL_DEFAULT must be set for surfaces passed to StretchRect and ColorFill"

If I change it to Pool.Default then I get the error "[4936] Direct3D9: (ERROR) :The destination surface must be created using D3DPOOL_SYSTEMMEM. GetRenderTargetData fails" Edited by Headkaze

Share this post


Link to post
Share on other sites

I think it would be better to create a dynamic texture, lock them both and copy the data manually.

 

IIRC, I tried doing something like this before, but ended up using D3DX's render to texture method instead (but that was for C++).

 

If you haven't already, you should look at the MSDN documentation for StretchRect[angle] and GetRenderTargetData.  I took a look myself but couldn't find a working solution either. unsure.png 

 

Shogun.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement