Sign in to follow this  

Making a getDC handle into a d3d texture?

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

hi, i have set up d3d9 to use D3DXCreateTextureFromFile to create a texture on my 2d plane but... rather than the source being a file i want to use a handle returned by the getdc function ): i am new to direct3d, i did this in direct draw a while back, but i have no idea how to do it in d3d also tried searching the net, but theres too much stuff that has nothing to do with what i want to do any info is appreciated, thanx (:

Share this post


Link to post
Share on other sites
My best guess would be to use GetDIBits() to get the bitmap data from the DC, and then use D3DXLoadSurfaceFromMemory() to copy the data from the DIBits to the surface of a texture that you create. Something along the lines of:

HBITMAP hBitmap = GetCurrentObject(hDC, OBJ_BITMAP);
pBitmapData = new BYTE[/*# Bytes Needed*/];
BITMAPINFOHEADER BitmapInfo;
/*Set values for BitmapInfo*/
GetDIBits(hDC, hBitmap, 0, Height, pBitmapData, &BitmapInfo, DIB_RGB_COLORS);
pD3DDevice->CreateTexture(/*...stuff...*/, &pTexture, NULL);
LPDIRECT3DSURFACE9 pSurface;
pTexture->GetSurfaceLevel(0, &pSurface);
D3DXLoadSurfaceFromMemory(/*...stuff...*/);
pSurface->Release();

(This is all pretty much a guess off the top of my head. Obviously not perfectly accurate, or guaranteed to work as is.)

Share this post


Link to post
Share on other sites
I just thought of something else. Instead of calling D3DXLoadSurfaceFromMemory, you could probably just create the texture, lock it, and then call GetDIBits(), using the pointer LockRect() gives you as the buffer into which GetDIBits() puts the data. The only problem with this is that you apparently cannot use a 32-bit texture, since GetDIBits() won't write data out in that format.

Share this post


Link to post
Share on other sites

This topic is 4762 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this