如何在Windows游戏上叠加图形? [英] How to overlay graphics on Windows games?

查看:163
本文介绍了如何在Windows游戏上叠加图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的程序能够启动任何Windows游戏,并且在用户玩游戏时,在游戏窗口的某个部分间歇性地显示一些文本或图片。游戏可能处于窗口模式或全屏模式。从我从网上资源中可以看出,这可以通过使用支持覆盖图的图形库来完成,并使用Windows挂钩来跟踪目标应用程序的窗口。在这方面,我有一些问题。


  1. 重叠会影响游戏性能吗?
  2. 如何挂钩应用程序会影响性能?
  3. / li>
  4. 有没有其他办法可以实现这个目标?例如,您如何看待 PIX , DirectX调试和分析工具,工作?


解决方案

Fraps 是从第三方应用程序向全屏DirectX应用程序执行此类操作的原型示例。它通过挂钩一些系统调用并将其自身插入到应用程序和DirectX之间的调用链中来工作。有一些性能受到打击,但总体来说是最小的。

此页面似乎有一些关于如何以这种方式挂接应用程序的细节和示例代码。



如果我记得其他论坛的讨论是正确的(目前找不到链接,搜索诸如fraps如何工作之类的东西,这是一个受欢迎的问题),Fraps挂钩了一些东西来强制应用程序加载它的DLL,然后调用Present()调用并在调用实际的Present()之前执行一个设备 - > Clear()调用,并将一个小矩形列表设置为不同的颜色,从而可以拼出它显示的FPS编号。这具有最小的性能影响,并且与应用程序正在进行的任何呈现相兼容。叠加位图会变得更加复杂,因为它在当前不会那么容易。也许如果你可以钩住EndScene,那么你可以做更多的事情,但你必须小心不要改变设备状态。



PIX有权限访问DirectX驱动程序,所以我不希望能够使用它作为模拟模型。



如果目标应用程序在窗口模式下运行,则挂接DirectX仍然可用,但你也可以直接使用GDI。



编辑:我认为这是我最初想到的链接。


I want my program to be able to launch any Windows game, and while the user is playing it, intermittently display some text or pictures in some part of the game window. The game may be in windowed or full-screen mode. From what I have been able to figure out from online resources, this could be done using a graphics library that supports overlays and using Windows Hooks to keep track of the target application's window. In this context I have some questions.

  1. Will the overlays affect the game's performance?
  2. How will hooking the application affect performance?
  3. Is there any other way one could achieve this? For example, how do you think PIX, the DirectX debugging and analysis tool, work?

解决方案

Fraps is the archetypal example of doing this sort of thing to a fullscreen DirectX application from a third-party app. It works by hooking some system calls and inserting itself into the call-chain between an app and DirectX. There is some performance hit, but in general its minimal.

This page seems to have some details and sample code on how to hook the app in this way.

If I recall correctly, from other forum discussions (can't find the link at the moment. search for things like "how does fraps work", it's a popular question), Fraps hooks a few things to force the app to load its DLL, then hooks Present() calls and executes a device->Clear() call before calling the real Present(), with a list of small rectangles to set to a different color, which can spell out the FPS number that it displays. This has a minimal performance impact and is widely compatible with whatever rendering the app is doing. Overlaying a bitmap would be more complicated since it wouldn't be as easy to do at Present-time. Perhaps if you could hook EndScene, then you could do more, but you would have to be careful to not change the device state.

PIX has privileged access to the DirectX driver, so I wouldn't expect to be able to use that as a model to emulate.

If an the target app is running in windowed mode, hooking DirectX still work, but you could also just use GDI instead.

Edit: I think this is the link I was originally thinking of.

这篇关于如何在Windows游戏上叠加图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆