Clear Screen with a transparent color

Started by
3 comments, last by Beem 12 years, 7 months ago
Hey all,
first of all I'm german so please excuse my grammar.
However, I want to Clear the Screen of my Direct3D9 Application with a transparent color and for that I use the following code:

hr = pD3DDevice->Clear(0,
NULL,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(0, 0, 0, 0),
1.0f,
0);

But it looks like the Alphachannel is still being ignored.
The Backbuffer format is: D3DFMT_A8R8G8B8
Oh and I think it's worth mentioning that I render on the desktop instead in a window.

So my question is, how do I get the background of my Direct3D scene to be transparent?
I hope you can help me out...thanks in advance,

Regards
el-enemigo

P,S. Here's a screenshot of my program
Advertisement
AFAIK Clear doesn't support alpha channels. It's best to switch to drawing using primitives or sprites (these cause no framedrop while regular lines and font objects will).

Take a look at the directx sample browser. I'm sure there's something about primitives!

EDIT: Looked it up and for me it's: "Tutorial 2: Vertices"
Thanks for the reply.

Are you sure about that?
'Cause MSDN says:
Color [in] Type: D3DCOLOR

Clear a render target to this ARGB color.

[/quote]
What kind of result you expect to get when clearing the screen with RGBA color value? You mean that the alpha values don't get written to the back buffer?

Color with alpha value doesn't make it transparent in every case. Alpha value is just 4th value attached to the RGB-color. Most of the time it is true that alpha values stand for transparency, but even then you have to define how the alpha values are used.

Simply put : clearing the screen with the a RGBA color value will fill/replace the entire (back)buffer with that RGBA color, regardless of the current content of the buffer.

Cheers!

Edit : I noticed that you want your program to blend to the desktop. I don't have answer to that question, but probably you'll need to blend your backbuffer to the window/desktop under it. AFAIK, Clear doesn't provide that kind of functionality.
There is no such thing as an alpha channel in the back buffer. If you want to blend with the desktop, you'll probably need to render to a GDI surface, then use a Windows API call to blend it to the desktop. Here is something I found on the topic of alpha blending in the windows API http://blog.duck17.net/post/Per-pixel-Alpha-Blending-in-Native-Win32-API.aspx.

This topic is closed to new replies.

Advertisement