



// myOwnStuff.h
#pragma once
#include
class CmyOwnStuff
{
public:
CmyOwnStuff(IDirect3DDevice9 *pD3DDevice);
~CmyOwnStuff(void);
void Render(void);
void OnLostDevice(void);
void OnResetDevice(void);
private:
IDirect3DDevice9* m_pD3DDevice;
ID3DXSprite* m_pBackgroundSprite;
IDirect3DTexture9* m_pBackgroundTexture;
};
// myOwnStuff.cpp
#include "StdAfx.h"
#include ".\myownstuff.h"
CmyOwnStuff::CmyOwnStuff(IDirect3DDevice9 *pD3DDevice)
{
extern HINSTANCE gl_hThisInstance;
m_pD3DDevice = pD3DDevice;
m_pBackgroundSprite = NULL;
m_pBackgroundTexture = NULL;
D3DXCreateSprite(m_pD3DDevice,&m_pBackgroundSprite);
D3DXCreateTextureFromResourceEx(m_pD3DDevice,
gl_hThisInstance,
MAKEINTRESOURCE(IDB_BITMAP1),
256,
128,
0,
NULL,
D3DFMT_UNKNOWN,
D3DPOOL_MANAGED,
D3DX_FILTER_NONE,
D3DX_FILTER_NONE,
0xFF000000,
NULL,
NULL,
&m_pBackgroundTexture);
}
CmyOwnStuff::~CmyOwnStuff(void)
{
if (m_pBackgroundSprite) m_pBackgroundSprite->Release();
if (m_pBackgroundTexture) m_pBackgroundTexture->Release();
}
void CmyOwnStuff::Render(void)
{
m_pD3DDevice->BeginScene();
m_pBackgroundSprite->Begin(NULL);
m_pBackgroundSprite->Draw(m_pBackgroundTexture,
NULL,
NULL,
NULL,
D3DCOLOR_ARGB(0xaa,0xff,0xff,0xff));
m_pBackgroundSprite->End();
m_pD3DDevice->EndScene();
}
void CmyOwnStuff::OnLostDevice(void)
{
m_pBackgroundSprite->OnLostDevice();
}
void CmyOwnStuff::OnResetDevice(void)
{
m_pBackgroundSprite->OnResetDevice();
}
// myIDirect3DDevice9.cpp
HRESULT myIDirect3DDevice9::Present(...)
{
// we may want to draw own things here before flipping surfaces
// ... draw own stuff ...
if (!m_pMyOwnStuff) m_pMyOwnStuff = new CmyOwnStuff(m_pIDirect3DDevice9);
if (m_pMyOwnStuff) m_pMyOwnStuff->Render();
// call original routine
HRESULT hres = m_pIDirect3DDevice9->Present( pSourceRect,
pDestRect,
hDestWindowOverride,
pDirtyRegion);
return (hres);
}
HRESULT myIDirect3DDevice9::Reset(...)
{
if (m_pMyOwnStuff) m_pMyOwnStuff->OnLostDevice();
if (m_pMyOwnStuff) m_pMyOwnStuff->OnResetDevice();
return(m_pIDirect3DDevice9->Reset(pPresentationParameters));
}
HRESULT myIDirect3DDevice9::Present(CONST RECT* pSourceRect,
CONST RECT* pDestRect,
HWND hDestWindowOverride,
CONST RGNDATA* pDirtyRegion)
{
// call original routine
HRESULT hres = m_pIDirect3DDevice9->Present(
pSourceRect,
pDestRect,
hDestWindowOverride,
pDirtyRegion);
// Flush the engine content
IDirect3DQuery9* mQuery = NULL;
this->CreateQuery(D3DQUERYTYPE_EVENT, &mQuery);
mQuery->Issue(D3DISSUE_END);
while(mQuery->GetData(NULL, 0, D3DGETDATA_FLUSH) == S_FALSE); // wait loop here
mQuery->Release();
// do anything you want here (e.g. capturing
// using the GDI), the frame is now rendered
// completely
return (hres);
}











