Jump to content

  • Log In with Google      Sign In   
  • Create Account


Screenshot to texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Headkaze   Members   -  Reputation: 583

Like
0Likes
Like

Posted 16 February 2013 - 01:54 AM

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;
}


Sponsor:

#2 Headkaze   Members   -  Reputation: 583

Like
0Likes
Like

Posted 16 February 2013 - 02:08 AM

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, 16 February 2013 - 02:09 AM.


#3 blueshogun96   Crossbones+   -  Reputation: 811

Like
1Likes
Like

Posted 18 February 2013 - 01:40 AM

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.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS