Jump to content
  • Advertisement
Sign in to follow this  
XIII

Cannot Draw Anything after Successfully Hooking Direct3D

This topic is 3713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I interested in Direct3D hook and I want to add a speedometer for a game. I followed the way in http://www.gamedev.net/community/forums/topic.asp?topic_id=359794. The function EndScene is successfully called by the game and my code to draw a picture or a triangle is also executed successfully with HRESULT 0. But it just does not display on the screen. I simple put my code before IDirect3DDevice9->EndScene() and I set back everything which I set using Set** function after drawing. But I tried the same code with another game (Need for Speed 11), the triangle or picture is displayed OK. I am confused. I think all the Direct3D9 games will call IDirect3DDevice9->EndScene() to end their drawing and I should be able to draw it as long as I add code in EndScene. But why does my code not always success? The code I draw a triangle is as follows. Could anyone give me some opinions? Thank you very much! typedef struct { float x; float y; float z; float rhw; DWORD color; }CUSTOMVERTEX3; #define D3DFVF_CUSTOMVERTEX3 (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) CUSTOMVERTEX3 vertices3[] = { {10, 30, 0.0f, 1.0f, D3DCOLOR_XRGB(255,0,0)}, {110, 30, 0.0f, 1.0f, D3DCOLOR_XRGB(255,0,0)}, {10, 130, 0.0f, 1.0f, D3DCOLOR_XRGB(255,0,0)} }; hr = m_pDevice->CreateVertexBuffer(sizeof(vertices3), 0, D3DFVF_CUSTOMVERTEX3, D3DPOOL_DEFAULT, &m_pVB3, NULL); if (FAILED(hr)) { return hr; } void *pVertices3 = NULL; m_pVB3->Lock(0, sizeof(vertices3), &pVertices3, 0); memcpy(pVertices3, vertices3, sizeof(vertices3)); m_pVB3->Unlock(); m_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); m_pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE ); m_pDevice->SetFVF( D3DFVF_CUSTOMVERTEX3 ); m_pDevice->SetStreamSource( 0, m_pVB3, 0, sizeof(CUSTOMVERTEX3) ); m_pDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 ); ...

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by freeworld
Are you presenting to the screen with the Present function?


No, I do not call Present because the code I write is hooked in the game process which calls EndScene and Present function. Thank you for the clue:)

Share this post


Link to post
Share on other sites
A game can call BeginScene() and EndScene() multiple times per frame if it wants to. I think you can also get away with drawing stuff between EndScene() and Present(). You could try hooking Present() instead and doing your drawing there to work round that.

Alternatively try drawing something simpler. Clearing some or more of the screen should work regardless of any weird render states that might be set.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!