Convert IDirect3DTexture9 to GDI HBITMAPs

Started by
1 comment, last by Photon Man 14 years, 10 months ago
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!
Advertisement
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.


hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

I'm Doomed!!!

Thanks!

This topic is closed to new replies.

Advertisement