Direct3D hook overlay
I am trying to achieve an effect like the program Fraps does, which is an overlay on top of a game, and to do this I am hooking the IDirect3DDevice9::EndScene
function and rendering stuff before calling the original function. However, when I render stuff, it messes up effects that the game has already drawn, and doesn't draw itself corre开发者_开发技巧ctly. My hook just looks like
HRESULT __stdcall endscene_hook(IDirect3DDevice9* id3d_device) {
if (pGameOverlay) {
pGameOverlay->Render();
}
return endscene_orig(dev);
}
wherer pGameOverlay
is just a pointer to a class whose Render
method just draws some stuff to the device it was set up with previously (not shown). Is there something else I should be doing?
I read somewhere that Fraps actually hooks the Present
method, instead of EndScene
. Is this correct, and if so, why? And can't you only have one BeginScene
/EndScene
pair in between calls to Present
?
You can definitely have multiple BeginScene/EndScene
for each Present, and it is actually quite a common practice. Usually a pair of BeginScene/EndScene
is used for each individual Render Target. (One example of additional render target might be a mirror, but there are many other uses for multiple render targets, like shadow buffers, or dedicated depth targets for postprocess effects).
Hooking Present is a lot safer, as this is the call which actually "displays" (Presents) whatever was done to the user, and therefore from the very definition there is one Present per frame (as this is exactly this Present which defines the frame).
精彩评论