Implement Alpha overlay learning notes in ddraw in wince6.0

Source: Internet
Author: User

Record and learn how to use the overlay surface of ddraw to implement the Alpha function under wince, so as not to forget it later.

 

The program was modified based on the ddraw mosquito program.

 

Change the original program overlay keycolor to Alpha.

 

As shown in the preceding example, determine whether the hardware is supported before using this function.

Ddoverlayfx ovfx;

Memset (& ovfx, 0, sizeof (ovfx ));
Ovfx. dwsize = sizeof (ovfx );
If (ddcaps. dwoverlaycaps & ddoverlaycaps_alphasrc)
{
// Dwupdateflags | = ddover_keysrcoverride;

// Ovfx. dcksrccolorkey. dwcolorspacelowvalue = 0; // black as the Color Key
// Ovfx. dcksrccolorkey. dwcolorspacehighvalue = 0;
}

 

Alpha has two modes: ddoverlaycaps_alphasrc and ddoverlaycaps_alphadest.

The difference between the two is:

Ddover_alphadest

 

 

The Alpha information, or the alpha channel page that belongs to the target page, serves as the alpha channel of the overwriting layer.

 

 

Ddover_alphasrc

 

 

 

The Alpha information, or the alpha channel page that is affiliated to the Source Page, serves as the source alpha channel of the overwriting layer.

 

 

 

 

 

 

 

How can we configure it to implement Alpha?

When using keycolor, you need to set dwupdateflags | = ddover_keysrcoverride

Alpha should also have similar parameters. Check the ddover_keysrcoverride definition.

Two variables may be related to Alpha.

# Define ddover_alphasrc 0x00000004
# Define ddover_alphasrx0g 0x00000008

 

Their role is

 

Ddover_alphasrc

 

 

 

The Alpha information, or the alpha channel page that is affiliated to the Source Page, serves as the source alpha channel of the overwriting layer.

 

 

 

 

 

Ddover_alphasrx0g

 

 

 

Increase the Alpha value (0 is not transparent ).

 

 

 

Let's look at the definition of ddoverlaycaps_alphasrc.

We found that ddoverlaycaps_alphasrnng is the same as ddoverlaycaps_alphasrc.

Therefore, you must set both

Ddover_alphasrc and ddover_alphasrnng

 

Dwupdateflags | = (ddover_alphasrc | ddover_alphasrx0g );

 

How can I set specific parameters?

Let's take a look at the ddoverlayfx struct.

Typedef struct _ ddoverlayfx
{
DWORD dwsize; // size of Structure

DWORD dwalphaconstbitdepth; // bit depth used to specify Alpha constant.
DWORD dwalphaconst; // constant to use as alpha channel.

Ddcolorkey dckdestcolorkey; // destcolorkey override
Ddcolorkey dcksrccolorkey; // destcolorkey override

} Ddoverlayfx, * lpddoverlayfx;

 

The following parameters are useful:

Dwalphaconstbitdepth
Bit depth used to specify the Alpha constant for a source.
Dwalphaconst
Constant to use as the alpha channel for a source.

 

Set the two parameters as needed.

 

DwalphaconstbitdepthControls the depth of a bitmap.

Dwalphaconst controls Alpha transparency

 

When these two parameters are set, we find that the expected functions are not implemented and there is no way, so we have to search for information online and find that what others use is

Ddover_alphaconstoverride

Check msdn

Flag Description

Ddover_alphaconstoverride

Uses the Alpha information specified by dwalphaconst from the lpddoverlayfx argument.

For this to be supported, the display hardware must support constant alpha blending, as indicated by ddoverlaycaps_alphaconstant.

In the past, ddover_alphaconstoverride was set to use the parameter specified by dwalphaconst.

To set ddover_alphaconstoverride, hardware must support ddoverlaycaps_alphaconstant.

So you can set it as follows:

If (ddcaps. dwoverlaycaps & ddoverlaycaps_alphaconstant)
{
Dwupdateflags | = ddover_alphaconstoverride;

Ovfx. dwalphaconst = 0x37;
Ovfx. dwalphaconstbitdepth = 8;
}

After completing the settings, build the following and OK to implement the Alpha overlaylay function.

 

Refer:

Microsoft msdn

Wince ddraw sample

Http://honwsn.itpub.net/post/41648/499213

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.