HDC from IDirect3DTexture9

Started by
5 comments, last by jollyjeffers 18 years, 8 months ago
Hi! I'm presently moving my 2D engine from DirectDraw to Direct 3D. I'm very happy about the result but I have a last important thing to do : How to get an HDC from an IDirect3DTexture9? Thanks you, Joe.
Advertisement
(1) Use IDirect3DTexture9::GetSurfaceLevel( 0 ) to retrieve a surface on the texture.

(2) Use IDirect3DSurface9::GetDC() to get the device context.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Thanks, it work well, but now, I have a Transparancy/Color Keying problem:
//---------------------------------------------------------------------// Members & initiationIDirect3DSurface9 *pds;LPDIRECT3DTEXTURE9 pTexture;HDC hDC;d3d.m_pd3dDevice->CreateTexture(800, 600, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &pTexture, NULL);// Set vertex for 2D on 3D.........// Draw the Texture with GDI function, and then, display itd3d.ClearBuffer();d3d.BeginDrawing();pTexture->GetSurfaceLevel(0, &pds);if( pds->GetDC( &hDC ) ){    TextOut(hDC, 10, 10, "Hello!", 6);    .... Other GDI draw.....    pds->ReleaseDC( hDC );    pds->Release();}//Set textured3d.m_pd3dDevice->SetTexture(0, pTexture);d3d.m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE,  TRUE);d3d.m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC,  D3DCMP_GREATEREQUAL);d3d.m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 0x01);d3d.m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);		// End drawing...d3d.EndDrawing();d3d.Present();//------------------------------------------------------------------------

It's work well, but it's show the entire 800x600 texture. (Black background) Can someone explain me why there's no transparency?

Joe.

[Edited by - Coder on August 21, 2005 2:57:15 PM]
You're creating an X8R8G8B8 texture - i.e. it doesn't hold any alpha information.

But the problem is that A8R8G8B8 texture is not compatible with :

pTexture->GetSurfaceLevel(0, &pds);
pds->GetDC( &hDC );
I can think of the following solutions. Smarter ones most probably exist:
1) Don't use GDI to draw the texture, do it another way.
2) Use a pixel shader, and emit an alpha of 0 if the input color's the same as your colorkey (a pixel shader constant).
3) Lock the texture after you draw to it, and copy it to another texture with alpha.

I've done more than enough messing about with texture memory to get to/from formats... and in my experience the "built in" functionality (be it GDI/DC's or the StretchRect/CopyRect stuff) is good so long as you stick to using it the way THEY want you to use it.

As soon as you step outside of the designated use you're pretty much back to square one.

In those cases, or at least my experience of those cases, you usually have to resort to locking the texture and reading out the data as appropriate.

If I were you, double check all the available tools with regards to converting textures to suitable formats, and if you can't get what you want you might just have to bite the bullet and implement your own routine [headshake]

hth
Jack

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

This topic is closed to new replies.

Advertisement