Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
What exactly are you trying to do? Take a screen shot, or make some type of reflection? Or something completely different?

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted (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 by EFileTahi-A
Posted

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

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted (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 by EFileTahi-A
Posted

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)

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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

Posted

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

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • 3 years later...
Posted

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!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...