Jump to content
  • Advertisement
Sign in to follow this  
Naphos

Making a getDC handle into a d3d texture?

This topic is 5042 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
Advertisement
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
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!