Jump to content
  • Advertisement
Sign in to follow this  
WarrickF

Off Screen Direct3D

This topic is 4004 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

Hi All, I've written a quick app that draws a simple canvas using Direct3D. I'd like to run this code as a service at the end of the day and hence do not want to render the output to the screen. Instead I'd like to save it to file in (BMP or some other format). I'm no Direct3D guru, but it seems like I'd want to write the contents of the back buffer to disk. Does anyone have any experience doing this or could point me at a link that would help? Thanks Warrick

Share this post


Link to post
Share on other sites
Advertisement
Typically a Windows Service cannot have nor interact with the GUI, so I think it unlikely that you'll be able to re-write your D3D application in this form. Even if you don't present to the screen you'll need to create the device against an HWND which I assume you can't get from within a Service...

It's things like this that tend to make it tricky to write server-side/back-end processing tools using Direct3D [headshake]

Jack

Share this post


Link to post
Share on other sites
Thanks Jack. I think you can get a HWND if you allow the service to interact with the desktop. What I'm really wanting to avoid is the overhead of moving the rendered frame to the front buffer and then out to file. What I was thinking is that I could do all the work in the back buffer and take the results straight from there.

I've seen things like DirectShow filters using Direct3D to overlay content and they are not interactive applications so I think it's possible. I'm just not much of a C++ programmer and looking for an easy way to do this is C#.

Share this post


Link to post
Share on other sites
You should be able to get a texture surface by creating a texture of the correct size which you can setup as the render target for D3D.You can render to the surface by grabbing it from the surface texture->GetSurfaceLevel and calling SetRenderTarget. You can then use the D3DXSaveSurfaceToFile to save it out again.

Share this post


Link to post
Share on other sites
To be honest you're talking a little above my head. I'm still VERY new to this. I've been trying to understand render targets for about an hour now and I'm still a little confused.

I also found this article:

http://www.pluralsight.com/wiki/default.aspx/Craig.DirectX/SaveToFileSample.html

Which uses SurfaceLoader.Save to do something like this:

SurfaceLoader.Save("c:\\out.jpg", ImageFileFormat.Jpg, device.GetBackBuffer(0, 0, BackBufferType.Mono));

This seemes to work and gives me access to the back buffer.

Of course I don't really know what the heck I'm doing so I'm not sure if I'm barking up the wrong tree or not :)

Share this post


Link to post
Share on other sites
You can easily do the rendering and save it out to the file without seeing the contents of the image (i.e. presenting it)... The "render to texture" method is your search term here - it's commonly used in post processing so there will be LOTS of examples online.

The problem I was highlighting is when creating the device - I'm pretty sure you can't create a headless device, but you might be able to do this with D3D9Ex/D3D10 though.

As a simple test, write a Windows Service that simply creates a device - if you can get that far then you should be okay with the rest.

hth
Jack

Share this post


Link to post
Share on other sites
Wow, that's a marathon argument. At least that answers the question though - Really poor design though in my opinion.

Thanks for everyone's help, it's very much appreciated.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!