Jump to content
  • Advertisement
cambalinho

Directx 9 with C++: how can i draw an image transparent?

Recommended Posts

see how i draw the image:

hResult= D3DXLoadSurfaceFromFile( surface,NULL,NULL,"C:\\Users\\Cambalinho\\Documents\\CB\\testdx\\Bleu Battle.bmp",NULL,D3DX_DEFAULT,D3DCOLOR_XRGB(255,255,255),NULL );
        if ( FAILED( hResult ) ) MessageBox(NULL,"Error","erro",MB_OK);

        //Draw the sprite:
        RECT imRect={100,50,158,130};//destination rect
        d3ddev->StretchRect(surface,NULL,backbuffer,&imRect, D3DTEXF_NONE);

the image isn't drawed transparent. the problem is the StretchRect() function or the 'surface' back color(it's black)?

Share this post


Link to post
Share on other sites
Advertisement
To render transparent images in general you want to load the image data with alpha information.  Your bitmap won’t contain this.  So alpha values for your texture will all be 0xff opaque.
For directx9 Best bet is to create a texture as 32 bit ARGB and then read in an image date file that contains the  A R G B raw data, then memcpy it into your texture/surface.  This link will give you a guide, although, it creates it’s own texture rather than memcpy one in.
https://msdn.microsoft.com/en-us/library/windows/desktop/bb206240(v=vs.85).aspx
 
If you want to D3DXLoadSurfaceFromFile to convert black (from your bitmap) to transparent black e.g. 0x00000000,  then this may be possible,I believe your color key setup is wrong see here.
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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!