Jump to content
  • Advertisement
Sign in to follow this  
Programmer101

Making a Surface Transparent

This topic is 4066 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

I have a bitmap for crosshairs that I am drawing to the screen using a "LPDIRECT3DSURFACE9" device. I got the backbuffer and loaded the surface with a transparency color. The only problem is when I draw it, no matter what the transparency color is, the part that should be transparent turns up black and blotches out all of the geometry behind it. How can I make it transparent?

Share this post


Link to post
Share on other sites
Advertisement
Oh. I didn't know you could do that with surfaces. Ok thanks I'll try it.

EDIT:

I just tried it and it doesn't change the results. Here is my code:

//Draw the HUD
g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_ALPHAREF, 0x01);
//-/Target
crossRect.top=height/2-16;
crossRect.left=width/2-16;
crossRect.bottom=height/2+16;
crossRect.right=width/2+16;
g_pD3DDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
g_pD3DDevice->StretchRect(cross, NULL, backbuffer, &crossRect, D3DTEXF_NONE);
//Done rendering HUD
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

Share this post


Link to post
Share on other sites
Sorry big misunderstanding. I thought you use the surface interface to fill a texture and then render a quad as this is the more correct way to render something.

StretchRect should only used in some special cases and not for rendering a HUD.

Share this post


Link to post
Share on other sites
Oh. Okay. What should I use then? I was going to use sprites but they didn't seem right because the coordinates were in 3d and it seemed like it would be too hard to calculate a D3DXVECTOR3 for each HUD element. If you are supposed to use a sprite, how do I do it?

Share this post


Link to post
Share on other sites
Quote:
Original post by Programmer101
Oh. Okay. What should I use then? I was going to use sprites but they didn't seem right because the coordinates were in 3d and it seemed like it would be too hard to calculate a D3DXVECTOR3 for each HUD element. If you are supposed to use a sprite, how do I do it?
Personally, I'd draw a series of textured quads (Same the D3DXSprite does, really) in screen space. You can do that by using transformed vertices (D3DFVF_XYZRHW if you're using the fixed function pipeline), or by using an orthogonal projection matrix (Which means the viewport will be like a CAD-style window where objects with a greater Z value aren't drawn smaller - See D3DXMatrixOrthoLH)

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!