EFileTahi-A Posted January 29, 2006 Posted January 29, 2006 How can this be done? I need to retrieve the backbuffer image and copy it to a texture or whatever device.present() is going to show back to a texture. Thank you Quote
Nate Bross Posted January 29, 2006 Posted January 29, 2006 What exactly are you trying to do? Take a screen shot, or make some type of reflection? Or something completely different? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted January 29, 2006 Posted January 29, 2006 If you are trying to take a screenshot, I nocked this class together to make it a bit easier; but it's not really necessary as it's just 1 line of code anyway. 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 Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
EFileTahi-A Posted January 30, 2006 Author Posted January 30, 2006 (edited) Hi, tks for the posts Nate, I'm 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. 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 can't 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? Edited January 30, 2006 by EFileTahi-A Quote
Nate Bross Posted January 30, 2006 Posted January 30, 2006 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 dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono) This returns a Direct3D.Surface object, not a texture, but it shouldn't be very difficult to convert it. HTH Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
EFileTahi-A Posted January 31, 2006 Author Posted January 31, 2006 (edited) 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. :) Edited January 31, 2006 by EFileTahi-A Quote
Nate Bross Posted January 31, 2006 Posted January 31, 2006 I haven't got a compiler here, but this should work. 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) Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Goose Posted February 4, 2006 Posted February 4, 2006 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 Quote
EFileTahi-A Posted February 7, 2006 Author Posted February 7, 2006 Thak you for your post once more Nate, but I must know how to scale textures before I can try this... Quote
Nate Bross Posted February 7, 2006 Posted February 7, 2006 I'm not sure if there is a faster way than SurfaceLoader.SaveToStream() There may be, I just don't know of it. As for scaling, see this article on MSDN, haven't had alot of time to read it, but maybe it can point you in the right direction. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawingtexturebrushclassscaletransformtopic.asp Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
SteelRaiden Posted May 27, 2009 Posted May 27, 2009 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!!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.