Copying the backbuffer's image back to a texture

If you are trying to take a screenshot, I nocked this class together to make it a bit easier; but its not really necessary as its just 1 line of code anyway.

Code:
    Public Class ScreenShot
        Public dxDevice As Direct3D.Device     

        Public Sub New(ByVal Device As Direct3D.Device)
            dxDevice = Device
        End Sub

        Public Sub TakeScreenShot()
            TakeShot()
        End Sub

        Private Sub TakeShot()
            SurfaceLoader.Save("test.jpg", ImageFileFormat.Jpg, dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono))
        End Sub
    End Class
 
Hi, tks for the posts Nate,

Im just trying to retrieve (at some point) all that is rendered in the backbuffer as image because I need to scale its contents +50%, and then, drawn back the scaled image to the screen.

Code:
Example:
[I](Pseucode)[/I]
You clear the screen (800x600) using black color;

[I]You draw the following into the back buffer[/I]
You draw a 300 pixel diameter circle;
You draw a 100x200 box;
And you draw 120x50 box;

[I]Now you retrieve all that is drawn so far and scale it by +50%[/I]
Texture = BackbufferContents;
ScaledImageTexture = Texture.Size +50%

You clear the screen again using black color
you draw the scaled image;

Continue drawing other graphics which are no needed to be scaled

If this is called screen shot, or some type of reflection, I really cant tell...

Just a question about the surfaceLoarder.Save, what kind of object is it? Can you add a line for me to see the way you declare it?
 
Last edited by a moderator:
SurfaceLoader is a built-in object into Direct3DX, see this for more information.

If you just want to get the BackBuffers contents you can use

Code:
dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono)

This returns a Direct3D.Surface object, not a texture, but it shouldnt be very difficult to convert it.

HTH
 
What If I asked you to drop me a line showing me how to get and convert the backbuffer into a texture? I would really apreciate that.

Netherthe less, thank you very much for your help so far. :)
 
Last edited by a moderator:
I havent got a compiler here, but this should work.


Code:
            Dim gs As GraphicsStream
            gs = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono))
            Dim bmp As New Bitmap(gs)
            Dim tx As New Texture(dxDevice, bmp, Usage.AutoGenerateMipMap, Pool.SystemMemory)
 
Multiple Pass Question

So I tried this and it worked great for accessing the texture in system memory from a single pass of a HLSL technique. My next question is: Is there a faster way to quickly get the texture back to the GPU so that the pixel shader in the second pass has access to it and can use it as int input? The SurfaceLoader.SaveToStream() is extremely slow since its writing the texture out to the system memory. It seems like there should be a faster way to do it without the intermediate texture going to the system memory and then back to the gpu. Thanks again
 
Nate Bross

YOU ARE THE BEST!!! This damn method drove me crazy...
The damn Movie.RenderToTexture method generates a texture and I searched for days how to save that texture in a bitmap... Someone says "use frontbuffer" yes but it is very slow... So "use textureloader.save" but is still slow... so "use surfaceloader.save" slow. Use that BackBuffer... FAST!! That what I need... take a bitmap from a video in a FAST way... thank you!!!
 
Back
Top