Followers 0

# How to set D3D rendering on the HDC I created?

## 2 posts in this topic

I have a window and I can get a HDC via GetDC() from the window. Now I want a cube rendering on the HDC that can be gotten from my own window, how should I do?

The rendering function looks like this:

void D3dRender(HDC myHdc)
{
//usual D3dRender on the HDC I provide
} 

Only can I find examples of rendering on the HDC created by D3D itself.

Thus I can pD3dSurface->GetDC(), but can't "pD3dSurface->SetDC()". Yes, there is no such method in IDirect3DSurface9 class.

0

##### Share on other sites

Direct3D Device object itself is basically a graphics device context. The GetDC method of the surface interface is provided for interoperability reasons (so you can draw to D3D surfaces with GDI).

You can redirect rendering given a window handle, though; the device's Present method optionally takes a HWND that represents the desktop area to present to.

If you only have the HDC of the window, you could use WindowFromDC function to get the associated HWND. Be sure to cache the HWND you get if you go this route; the function is heavier than you might think.

Edited by Nik02
2

##### Share on other sites

Direct3D Device object itself is basically a graphics device context. The GetDC method of the surface interface is provided for interoperability reasons (so you can draw to D3D surfaces with GDI).

You can redirect rendering given a window handle, though; the device's Present method optionally takes a HWND that represents the desktop area to present to.

If you only have the HDC of the window, you could use WindowFromDC function to get the associated HWND. Be sure to cache the HWND you get if you go this route; the function is heavier than you might think.

0

## Create an account

Register a new account

Followers 0

• 28
• 13
• 11
• 31
• 20