Sign in to follow this  
Drexl

Direct3D: Using colorkeying with StretchRect?

Recommended Posts

I´m using StretchRect to draw the background in my game. I want to use colorkeying so I can make certain areas of the bitmap transparent. But now Im getting FRUSTRATED, I cant get the damn colorkeying to work. The thing that happens is that the color that I want transparent gets rendered BLACK. Ok, this is the parts of my code dealing with my background, can anyone spot what Im doing wrong? Please help me! //Create a surface for the background bitmap. if(FAILED(g_pDirect3DDevice->CreateOffscreenPlainSurface( 640, 480, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_pBackground, NULL ))) { return(E_FAIL); } //Load the background bitmap into the surface. if(FAILED(D3DXLoadSurfaceFromFile( g_pBackground, NULL, NULL, "background.bmp", NULL, D3DX_DEFAULT, D3DCOLOR_RGBA(255,0,255,255), NULL ))) { return(E_FAIL); } //Set rendering states g_pDirect3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); g_pDirect3DDevice->SetRenderState(D3DRS_ALPHAREF, 0x01); g_pDirect3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); g_pDirect3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); //Render the background g_pDirect3DDevice->StretchRect(g_pBackground, &SrcRect, g_pBackBuffer, &DestRect, D3DTEXF_NONE);

Share this post


Link to post
Share on other sites
I'm not sure if colorkeying is possible with StretchRect (I don't think it is), but SetRenderState only effects render calls not surface blitting.

I would recommend either using D3DXSprite or making your own textured quad encapsulation. You will be able to do much more just as easilly.

Share this post


Link to post
Share on other sites
I am using D3DXSprite for rendering my small moving objects. I tried to use that interface to render the background, but I noticed that it couldnt handle large bitmaps (about 200*200 and larger), which resulted in distorted, stretched bitmaps on the screen. I would be forced to partition my background into 16 or more smaller bitmaps. And that is what I am forced to do if I cant get StretchRect to work, or find some other interface to help me draw my background.

I could use the DirectDraw function Blt, but isnt that an obsolete technique when you want to program 2D games nowadays?

Share this post


Link to post
Share on other sites
I'm pretty sure you should be able to get the D3DXSprite stuff to draw large images correctly as well. You probably just need to examine the documentation more closely. I haven't used D3DXSprite myself, but I do know that with more manual methods of drawing sprites (which are most certainly similar to what D3DXSprite does under the hood), getting a flag or some other minor thing wrong will indeed cause problems like you described. But it's definitely very doable once you get everything right.

Share this post


Link to post
Share on other sites
Believe me, I´ve looked through the documentation very closely for the past weeks, without result. It seems I´ve tried everything to get the darn thing to work properly. I too think its just a simple little flag or something that should be set correctly to get it to work. So, is there anyone how can help me with this?

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

Sign in to follow this