Advertisement Jump to content
Sign in to follow this  
Juliean

Windows cursor transparency

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

Hello,

 

I'm trying to load a mouse cursor for windows from an image-file. How do I calculate the correct and + xor-masks for transparent images? I'm using the method from CodeProject.com, which works fine for simple cursors without an alpha-channel:

gfx::TextureAccessorX32 accessor(texture, true);
const gfx::Color3 transparent(254, 254, 254);
for(unsigned int x = 0; x < (unsigned int)vSize.x; x++)
{
    for(unsigned int y = 0; y < (unsigned int)vSize.y; y++)
    {
        auto& pixel = accessor.GetPixel(x, y);

        if(pixel == transparent)
        {
            SetPixel(hAndMaskDC, x, y, RGB(255, 255, 255));
            SetPixel(hXorMaskDC, x, y, RGB(0, 0, 0));
        }
        else
        {
            SetPixel(hAndMaskDC, x, y, RGB(0, 0, 0));
            SetPixel(hXorMaskDC, x, y, RGB(pixel.r, pixel.g, pixel.b));
        }
    }
}

One color is marked transparent and everything is fine. But for alpha-channel-textures, the best I got was:

gfx::TextureAccessorA32 accessor(texture, true);
for(unsigned int x = 0; x < (unsigned int)vSize.x; x++)
{
	for(unsigned int y = 0; y < (unsigned int)vSize.y; y++)
	{
		auto& pixel = accessor.GetPixel(x, y);

		const unsigned int invAlpha = 255 - pixel.a;
		SetPixel(hAndMaskDC, x, y, RGB(invAlpha, invAlpha, invAlpha));
		SetPixel(hXorMaskDC, x, y, RGB(pixel.r, pixel.g, pixel.b));
	}
}

Which doesn't even produce results near what I'm expecting. Anyone familiar with the algorithm I need here?

Share this post


Link to post
Share on other sites
Advertisement

Why not use a specialized app for this? Does it really have to be generated "on-the-fly"? A few cursors only take a little disk space after all.

Share this post


Link to post
Share on other sites

Why not use a specialized app for this? Does it really have to be generated "on-the-fly"? A few cursors only take a little disk space after all.

 

It does not really have to be on-the-fly 100%, but I prefer the ease of using simple image-files rather than having to relate to external tools for creating the cursors. I also sort of have cross-plattform into mind, and though it is a bit pre-maturely I quess that doing so will make it easier when it comes to it.

 

 

 


You don't use an bitwise mask for an alphablended cursor. Bitwise mask can only give you on/off transparency.

See http://support.microsoft.com/kb/318876 for example of how to make alphablended cursors.

 

Thanks, thats what I've been looking for! Now I only need to tell microsoft to stop translating that article to german - poorly auto-translated article in my primary language is harder to read than english article biggrin.png

Edited by Juliean

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!