简体   繁体   English

如何在Windows 7上自动支持XNA中的单显示器或双显示器?

[英]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. 我正在使用Microsoft XNA创建一个游戏应用程序,它将在一个面向公众的屏幕(投影仪)上运行,并在笔记本电脑屏幕上显示控件(Windows 7)。当第二个显示器不可用时,我只想面向公众屏幕显示在笔记本电脑的屏幕上。 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() 检查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 您可以在http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1上阅读有关如何在XNA中使用WinForms的信息。

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 您正在通过WinForms使用XNA

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. 您可以让渲染服务器对两个单独的RenderTarget2D(或主屏幕,然后在rendertarget上)执行所有实际渲染,然后将一个rendertarget传输到客户端以渲染到辅助屏幕。 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. 将数据传输到客户端应用程序可以通过多种方式完成,但在这种情况下,我个人最喜欢的是内存映射文件,用于将rendertarget的字节数据传输到第二个。 Otherwise tcp communication should be used for performance. 否则应该使用tcp通信来提高性能。 If you need info on extracting byte data or transfering to the other application simply comment on my post. 如果您需要有关提取字节数据或转移到其他应用程序的信息,只需评论我的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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