Advertisement Jump to content
Sign in to follow this  
Photon Man

Convert IDirect3DTexture9 to GDI HBITMAPs

This topic is 3517 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 have an IDirect3DTexture9 that needs to be converted to (maybe an HBitmap?) or something that GDI can draw out to a window. I just can't seem to convert the actual RGB data of the IDirect3DTexture9 to an acceptable format for the GDI. I'm new to GDI, so source examples would be great. Thanks!

Share this post

Link to post
Share on other sites
I only recommend you try doing this if you enjoy punishing yourself. GDI=pain. [wink]

This page has a reasonably good overview of the steps involved. It's most efficient if you create a surface and use SetDIBits() but it is pretty fiddly getting all of the BGR24's encoded correctly (inc. alignment).

Alternatively you can follow similar steps and cheat with SetPixel() which is much slower but hides much of the GDI complexity for you.

As for converting the format - I'm pretty sure GDI DIB's are BGR24, which is backwards to direct3d, so if you have a D3DFMT_X8R8G8B8 it's as simple as swapping the R and B bytes. For 16bit formats it gets much hairier and you need to scale up from 5 or 6 bits to 8 and reorder - a simple bit shift can work, but for quality you may want a more sophisticated algorithm.


Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!