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

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

问题描述

我希望我的程序能够启动任何 Windows 游戏,并且在用户玩游戏时,在游戏窗口的某些部分间歇性地显示一些文本或图片.游戏可能处于窗口或全屏模式.从我从在线资源中了解到的情况来看,这可以使用支持覆盖的图形库并使用 Windows Hooks 来跟踪目标应用程序的窗口来完成.在这种情况下,我有一些问题.

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. 叠加层会影响游戏的性能吗?
  2. 挂钩应用程序将如何影响性能?
  3. 有没有其他方法可以实现这一目标?例如,您如何看待 PIX,DirectX 调试和分析工具,有用吗?
  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 是执行此类操作的典型示例从第三方应用程序到全屏 DirectX 应用程序.它通过挂钩一些系统调用并将其自身插入应用程序和 DirectX 之间的调用链来工作.性能受到一些影响,但总体来说影响很小.

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.

如果我没记错的话,从其他论坛讨论中(目前找不到链接.搜索诸如fraps 是如何工作的"之类的内容,这是一个流行的问题),Fraps 挂钩了一些东西来强制应用程序加载它的 DLL,然后钩住 Present() 调用并在调用真正的 Present() 之前执行一个 device->Clear() 调用,用一个小矩形列表设置为不同的颜色,这可以拼出它的 FPS 数字显示.这对性能的影响最小,并且与应用程序正在执行的任何渲染广泛兼容.覆盖位图会更复杂,因为在当前这并不容易.或许,如果您可以挂钩 EndScene,那么您可以做更多的事情,但您必须小心不要更改设备状态.

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 拥有对 DirectX 驱动程序的特权访问权限,因此我不希望能够将其用作要模拟的模型.

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

如果目标应用程序在窗口模式下运行,挂钩 DirectX 仍然有效,但您也可以只使用 GDI.

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

我认为这个是我最初想到的链接.

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

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

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