Jump to content
  • Advertisement
Sign in to follow this  
JoeLaBanane

HDC from IDirect3DTexture9

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

Share this post


Link to post
Share on other sites
Advertisement
(1) Use IDirect3DTexture9::GetSurfaceLevel( 0 ) to retrieve a surface on the texture.

(2) Use IDirect3DSurface9::GetDC() to get the device context.

Share this post


Link to post
Share on other sites
Thanks, it work well, but now, I have a Transparancy/Color Keying problem:

//---------------------------------------------------------------------
// Members & initiation
IDirect3DSurface9 *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 it
d3d.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 texture
d3d.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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

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!