Jump to content
  • Advertisement
Sign in to follow this  
dist0rted

Direct3D 9: Transparent Surfaces?

This topic is 5061 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've been learning the 2D implementations of Direct3D 9 and working on my own interface to them called DGLib (Distorted Graphics Library), which you can find at http://www.dist0rted.com/index.php?Content=Programming Right now I'm wondering if I can make surfaces with LPDIRECT3DSURFACE9 transparent for text drawing. I'm doing this for the DGLoadText() and DGDrawText() functions which you can find in http://www.dist0rted.com/dglib.h and http://www.dist0rted.com/dglib.cpp as well as a demonstration of how to use them in http://www.dist0rted.com/main.cpp My current method is to use Direct3DDevice->ColorFill() to fill the text surface with a defined color, but I'd *really* like for it to be transparent. Thanks, Steven Welch

Share this post


Link to post
Share on other sites
Advertisement
If you are copying the surfaces around then no, there is no transparency. If you define a surface with alpha and use CopyRect to copy it onto the back buffer all transparent areas will be painted black. To my knowledge the only way to get transparency when directly modifying the back buffer is to do it your self, i.e. traverse through the surface, one pixel at a time, and do a check to see if it is opaque or not.

Chris

Share this post


Link to post
Share on other sites
I'm not drawing directly to the back buffer; I'm using individual surfaces and using StretchRect() to blit them to the back buffer. You can see in the files.

Share this post


Link to post
Share on other sites
StretchRect has the same issue as CopyRect, which is a major bummer. I will take a look at the source files to confirm what I am thinking.

[edit]
So I looked at the sourec files and it will not work setting the color fill to be transparent or loading a transparent image onto the surface. What you will get is a black box.

As a side note, I am not completely sure you need the BeginScene and EndScene calls since all you are doing is calling StrecthRect and not setting up texture stages, vertex buffers, and everything else dealing with 3D.

Chris

Share this post


Link to post
Share on other sites
The beginscene and endscene calls are in DGBeginScene() and DGEndScene()...

Anywho I know that the product is a black box, I wrote it :) Is there a way I can capture an image of the screen and paint the background to the surface?

Share this post


Link to post
Share on other sites
To reword what others have said: You cannot Alpha-Blend using the BLIT mechanisms within directx. CopyRect, StretchRect, UpdateSurface, ect. copy pixel data from a source to a target, replacing the pixel data in the destination rectangle.

In order to alpha blend (draw one image with transparency on top of another) you will need to use textures not surfaces. If you would like to keep things as simple as possible, I would recomend using the ID3DXSprite Interface.

The ID3DXSprite Interface supports scaling, rotation and if you want you can even give it a transformation matrix and use simple sprites in 3d. However you don't have to. The ID3DXSprite interface uses the Direct3D rendering pipeline, so you can utilize all rendering states - specifically D3DRS_ALPHABLENDENABLE.

Hope that helps.

Share this post


Link to post
Share on other sites
Not sure about getting the front buffer and storing it in the surface. Most of the books that I have seen have their own StretchRect code that handles transparency for them.

Chris

Share this post


Link to post
Share on other sites
Quote:
Is there a way I can capture an image of the screen and paint the background to the surface?


The pd3dDevice->GetBackBuffer () function retreives a pointer to the back buffer surface, which you can then copy or do with what you like.

If you are trying to get a screen shot then you can use pd3dDevice->GetFrontBufferData() - BUT - it is extremely slow and couldn't be used in a real time loop, so if you want a copy of the front buffer in real time then make a copy of the back-buffer before you call Present().

By (the surface) do you mean the back buffer?

Share this post


Link to post
Share on other sites
Quote:

The pd3dDevice->GetBackBuffer () function retreives a pointer to the back buffer surface, which you can then copy or do with what you like.


I guess nobody looks at the source code...

Anywho thanks anyway, I think I'll do it like this:

I'll force the programmer to make a certain image the background image or something like that and draw text onto that surface before all of the other bitmaps are rendered. This way they're all transparent except for the fact that the DGDrawBitmap() images will be shown on top of them.

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!