在现有图形应用程序上绘制DirectX/OpenGL图形 [英] Draw DirectX/OpenGL Graphics on an existing graphics application

查看:63
本文介绍了在现有图形应用程序上绘制DirectX/OpenGL图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,如果我已经回答了,请立即道歉,因为我可能只是在不规则的搜索条件下进行搜索.

First off, let me just apologize right off the bat in case this is already answered, because I might just be searching it under irregular search terms.

我正在寻找在使用DirectX绘制自己的图形(游戏)的应用程序中绘制2D图形的方法.我将通过向应用程序中注入DLL(我对此没有疑问,我可以做到这一点)并绘制图形来做到这一点.但是我不是真正擅长DirectX/OpenGL,但有两个基本问题要问.

I am looking to draw 2D graphics in an application that uses DirectX to draw its own graphics (A game). I will be doing that by injecting a DLL into the application (that part I have no questions about, I can do that), and drawing my graphics. But not being really good at DirectX/OpenGL, I have a couple of fundamental questions to ask.

1)为了在该窗口上绘制图形,我是否需要从过程存储器中获取预先存在的上下文,以及某种绘制场景的句柄?

1) In order to draw graphics on that window, will I need to get a pre-existing context from the process memory, some sort of handle to the drawing scene?

2)如果应用程序使用DirectX,我可以在其上使用OpenGL图形吗?

2) If the application uses DirectX, can I use OpenGL graphics on it?

请告诉我如何处理此问题.任何细节将不胜感激:-)预先谢谢你.

Please let me know as to how I can approach this. Any details will be appreciated :-) Thank you in advance.

推荐答案

"1)为了在该窗口上绘制图形,我需要从进程内存中获取预先存在的上下文,以及绘画场景?"

"1) In order to draw graphics on that window, will I need to get a pre-existing context from the process memory, some sort of handle to the drawing scene?"

是的,您需要确保您的钩子抓住了重要的上下文创建功能.例如,d3d中CreateDevice的所有变体都对您很有趣.

Yes, you need to make sure your hooks catch the important context creation functions. For example, all variations of CreateDevice in d3d are interesting to you.

您没有提到要使用哪个DirectX,但是两个版本之间存在一些差异.例如,在DirectX 9中,您对以下功能最感兴趣:1.创建/返回IDirect3DSwapChain9对象2.创建/返回IDirect3DDevice9,IDirect3DDevice9Ex对象

You didn't mention which DirectX you are using, but there are some differences between the versions. For example, At DirectX 9 you'd be mostly interested in functions that: 1. Create/return IDirect3DSwapChain9 objects 2. Create/return IDirect3DDevice9,IDirect3DDevice9Ex objects

在较新版本的DirectX中,它们的代码分为(主要是)Device,DeviceContext和&DXGI.如果您要执行特定任务",请共享要处理的DirectX版本.

In newer versions of DirectX their code was splitted into (mostly) Device, DeviceContext, & DXGI. If you are on a "specific mission" share which directx version you are addressing.

除了捕获所有需要的对象以允许自己渲染外,您还希望捕获所有演示事件(GL中为"SwapBuffers",DX中为"Present"),因为那时候您要添加叠加层.

Apart from catching all the needed objects to allow your own rendering, you also want to catch all presentation events ("SwapBuffers" in GL, "Present" in DX), Because that's time that you want to add your overlay.

由于您似乎正在尝试在DX应用程序上渲染叠加层,因此让我警告您,制作一个真正通用的解决方案(适用于所有游戏)并不容易.主要是由于需要支持不同的DX版本以及多种创建方法如果您专注于特定的游戏/应用程序,那么自然会容易得多.

Since it seems that you are attempting to render an overlay on top of DX applications, allow me to warn you that making a truly generic solution (that works on all games) isn't easy. mostly due to need to support different DX versions along with numerous ways to create If you are focused on a specific game/application it is, naturally, much easier.

"2.如果应用程序使用DirectX,我可以在其上使用OpenGL图形吗?"

"2. If the application uses DirectX, can I use OpenGL graphics on it?"

首先,是的.这是可能的.您要搜索的术语是OpenGL DirectX互操作性(或简称互操作性)

Well, first of all yes. It's possible. The terminology that you want to search for is OpenGL DirectX interoperability (or in short interop)

这是一个例子: https://sites.google.com/site/snippetsanddriblits/OpenglDxInterop 我不知道他们使用的扩展名是否仅在nVidia设备中可用-对其进行检查.

Here's an example: https://sites.google.com/site/snippetsanddriblits/OpenglDxInterop I don't know if the extension they used is only available in nVidia devices or not - check it.

与此有关的另一件事是,您需要一个非常好的动力才能做到这一点,通常,我通常会坚持使用DX进行挂钩和渲染.我认为不同DX版本之间的内部互操作是更好的选择.我个人可能会使用DirectX9作为您自己的渲染代码.当然,如果只需要支持一个DirectX版本,则不需要互操作.

Another thing about this is that you need a really good motivation in order to do it, generally I would simply stick with DX for both hooking and rendering. I assume that internal interop between different DX version is better option. I'd personally probably go with DirectX9 for your own rendering code. Of course, if you only need to support a single DirectX version, no interop needed.

奖金:如果您需要生成C ++类的完整包装器,快速的肮脏的dll包装器或只是常规的全局函数挂钩,请随时使用我创建的此lib: http://code.google.com/p/hookit/它远不是一个经过全面测试的工具,只是我破解了2天的工具,但我发现它非常有用.

Bonus: If you ever need to generate full wrappers of C++ classes, a quick n' dirty dll wrapper, or just general global function hook, feel free to use this lib that i created: http://code.google.com/p/hookit/ It's far from a fully tested tool, just something i hacked 2 days, but I found it super useful.

请注意,在您的情况下,我建议仅使用VTable挂钩,您可能必须将函数offset硬编码到表中,但这不太可能改变.

Note that in your case, i recommend just to use VTable hooking, you'll probably have to hardcode the function offset into the table, but that's not likely to change.

祝你好运:)

这篇关于在现有图形应用程序上绘制DirectX/OpenGL图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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