Jump to content
  • Advertisement
Sign in to follow this  
langtudontinh

Direct3D: Howto get DC from BackBuffer?

This topic is 4885 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

Hello, I'm working on Direct3D version 9.0, I want to render some basic shapes: line, circle, elipse, polygon,... (they should support line style - dash, dot; line color, thickness). The problem here is I could not get device context from the backbuffer. I dont want to use offscreensurface (this type of surface could be obtained DC) because it seems too slow when I updated from offscreensurface to backbuffer surface. The code: HRESULT Render() { m_pd3dDevice->BeginScene(); //render texture, mesh,... LPDIRECT3DSURFACE9 pSurf = NULL; m_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurf); HDC hDC; if (D3D_OK!=pSurf->GetDC(&hDC)) MessageBox(NULL, "How come?", "", MB_OK); ::Rectangle(hDC, 100,100,500,500); pSurf->ReleaseDC(hDC); pSurf->Release(); m_pd3dDevice->EndScene(); return m_pd3dDevice->Present(NULL, NULL, NULL, NULL); } Pls, show me how to solve this problem. OR, provide another way to render these shapes. Thanks in advance. ltdt.

Share this post


Link to post
Share on other sites
Advertisement
My knowledge about DirectX is definately not up to date but I'd try requesting a DC outside of BeginScene/EndScene.

Share this post


Link to post
Share on other sites
/* Copies from documentation */

IDirect3DSurface9::GetDC fails on render targets unless they were created lockable (or, in the case of back buffers,
with the D3DPRESENTFLAG_LOCKABLE_BACKBUFFER flag).

For surfaces not created with IDirect3DDevice9::CreateOffscreenPlainSurface, IDirect3DSurface9::GetDC
will fail on default pool (D3DPOOL_DEFAULT) surfaces unless they are dynamic (D3DUSAGE_DYNAMIC) or are
lockable render targets.

Did you check both?

Greetz,

Illco

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!