简体   繁体   中英

How should I automatically support single or double monitors in XNA on Windows 7?

I'm creating a game application using Microsoft XNA that will run on one public-facing screen (projector) with controls on the laptop screen (Windows 7.) When the second monitor is not available, I'd like only the public-facing screen to show on the laptop screen. The proportions of the screens will be identical.

Is there a library to allow us to do this automatically, or at worst by changing a setting?

Check if there are two monitors available with GraphicsAdapter.Adapters.Count()

If there are, create another form, and set it to the second monitor (projector). Then, with every frame, render your public-facing interface onto the secondary monitor, and draw the controls onto the primary.

To switch between forms, just swap the handles:

graphics.GraphicsDevice.Present(form1.Handle);

Otherwise, draw the public-facing only.

You can read about how to use WinForms with XNA at http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1

This solution assumes two things:

  • that the primary display is set to the laptop's display and the second monitor isw set to extend (and not mirror)
  • you are using XNA through WinForms

The best way I can think of on the top of my head would involve creating a rendering server and a client application.

You can have the rendering server do all the actual rendering to two separate RenderTarget2D (or the main screen and then on a rendertarget) and then transfer one rendertarget to the client for rendering to the secondary screen. This means that the client application is super-lightweight and will only involve rendering a texture to full screen.

Transfering data to the client application can be done in many ways, but my personal favourite in this situation would be a memory mapped file to transfer the byte data of the rendertarget to the second. Otherwise tcp communication should be used for performance. If you need info on extracting byte data or transfering to the other application simply comment on my post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM