Discussion:
Transparent cursor problem when creating OpenGL context
(too old to reply)
Justin Bozalina
2007-03-28 14:30:04 UTC
Permalink
I'm running VS 2005. The application I develop for uses a "shaping tool"
cursor at some points, replacing the cursor with a transparent bitmap. It
does this by creating a bitmap, testing the colors of the bitmap to set the
alpha values, then using CreateIconIndirect to create an HCURSOR, as seen
below.

This normally works correctly. However, we've observed that when both third
party and our own add-ons to the software create an OpenGL context for
on-screen and off-screen rendering, the cursor does not display as expected.
Instead of displaying the entire cursor bitmap, it won't display anything
larger than 61 pixels, in the x or y dimensions. Once the OpenGL context is
destroyed, it goes back to working as it should.

Also peculiar, when running OpenGL, the entire cursor bitmap WILL display
correctly if the transparency of the bitmap is not altered (the double for
loop is commented out). This occurs on every computer we run this on, ATI
and NVIDIA cards, otherwise I would think it was an OpenGL issue. Any ideas?

lpdwPixel is a pointer to the DIB bit values, as returned from
CreateDIBSection. ptSizeDP is the size of the bitmap, in device coordinates.

// Set the alpha values for each pixel in the cursor so that the cursor is
semi-transparent.
DWORD* lpdwPixel;
lpdwPixel = (DWORD*)lpBits;
DWORD dwBlack = 0x00000000;
DWORD dwWhite = 0x00FFFFFF;

for( int x = 0; x < ptSizeDP.x; x++ )
for( int y = 0; y < ptSizeDP.y; y++ )
{
// Clear the alpha bits (this will make all bits transparent).
*lpdwPixel &= 0x00FFFFFF;

//If pixel is black, set the alpha bit to opaque.
if( *lpdwPixel == dwBlack )
*lpdwPixel |= 0xFF000000;
//If pixel is white, set the alpha bits to 0x4F (semi-transparent)
else if( *lpdwPixel == dwWhite )
*lpdwPixel |= 0x4F000000;

lpdwPixel++;
}

//Create the icon info structure.
ICONINFO ii;
ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
ii.xHotspot = ptSizeDP.x / 2;
ii.yHotspot = ptSizeDP.y / 2;
ii.hbmMask = hMonoBitmap;
ii.hbmColor = hBitmap;

// Create the alpha cursor with the alpha DIB section.
hAlphaCursor = CreateIconIndirect( &ii );
SetCursor( hAlphaCursor );
Alex Cohn
2007-04-10 10:44:02 UTC
Permalink
Post by Justin Bozalina
I'm running VS 2005. The application I develop for uses a "shaping tool"
cursor at some points, replacing the cursor with a transparent bitmap. It
does this by creating a bitmap, testing the colors of the bitmap to set the
alpha values, then using CreateIconIndirect to create an HCURSOR, as seen
below.
This normally works correctly. However, we've observed that when both third
party and our own add-ons to the software create an OpenGL context for
on-screen and off-screen rendering, the cursor does not display as expected.
Instead of displaying the entire cursor bitmap, it won't display anything
larger than 61 pixels, in the x or y dimensions. Once the OpenGL context is
destroyed, it goes back to working as it should.
Also peculiar, when running OpenGL, the entire cursor bitmap WILL display
correctly if the transparency of the bitmap is not altered (the double for
loop is commented out). This occurs on every computer we run this on, ATI
and NVIDIA cards, otherwise I would think it was an OpenGL issue. Any ideas?
lpdwPixel is a pointer to the DIB bit values, as returned from
CreateDIBSection. ptSizeDP is the size of the bitmap, in device coordinates.
// Set the alpha values for each pixel in the cursor so that the cursor is
semi-transparent.
DWORD* lpdwPixel;
lpdwPixel = (DWORD*)lpBits;
DWORD dwBlack = 0x00000000;
DWORD dwWhite = 0x00FFFFFF;
for( int x = 0; x < ptSizeDP.x; x++ )
for( int y = 0; y < ptSizeDP.y; y++ )
{
// Clear the alpha bits (this will make all bits transparent).
*lpdwPixel &= 0x00FFFFFF;
//If pixel is black, set the alpha bit to opaque.
if( *lpdwPixel == dwBlack )
*lpdwPixel |= 0xFF000000;
//If pixel is white, set the alpha bits to 0x4F (semi-transparent)
else if( *lpdwPixel == dwWhite )
*lpdwPixel |= 0x4F000000;
lpdwPixel++;
}
//Create the icon info structure.
ICONINFO ii;
ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
ii.xHotspot = ptSizeDP.x / 2;
ii.yHotspot = ptSizeDP.y / 2;
ii.hbmMask = hMonoBitmap;
ii.hbmColor = hBitmap;
// Create the alpha cursor with the alpha DIB section.
hAlphaCursor = CreateIconIndirect( &ii );
SetCursor( hAlphaCursor );
I wonder, does this work correctly if you use the AND/XOR bitmaps without
setting the semi-transparent pixels? If it does, you can use dithering
instead of alpha...
Steve LaBar
2007-04-10 21:20:02 UTC
Permalink
No, if I set up a standard cursor using AND/XOR bitmaps, the cursor works
correctly as long as it is entirely opaque. As soon as I create the mask in
such a way as to have a transparent section of the cursor, even a single
pixel, I get the clipping problem again.

Here is some additional information Justin and I have discovered since. We
did test it on an ATI card and it worked correctly, so it appears to be just
with Nvidia cards (contrary to below). Also, if you turn-off cursor and
bitmap hardware acceleration in the Display applet, the problem goes away.
We currently believe this to be a problem with the Nvidia driver.

Wonder if anyone else has run into this problem.
Post by Alex Cohn
Post by Justin Bozalina
I'm running VS 2005. The application I develop for uses a "shaping tool"
cursor at some points, replacing the cursor with a transparent bitmap. It
does this by creating a bitmap, testing the colors of the bitmap to set the
alpha values, then using CreateIconIndirect to create an HCURSOR, as seen
below.
This normally works correctly. However, we've observed that when both third
party and our own add-ons to the software create an OpenGL context for
on-screen and off-screen rendering, the cursor does not display as expected.
Instead of displaying the entire cursor bitmap, it won't display anything
larger than 61 pixels, in the x or y dimensions. Once the OpenGL context is
destroyed, it goes back to working as it should.
Also peculiar, when running OpenGL, the entire cursor bitmap WILL display
correctly if the transparency of the bitmap is not altered (the double for
loop is commented out). This occurs on every computer we run this on, ATI
and NVIDIA cards, otherwise I would think it was an OpenGL issue. Any ideas?
lpdwPixel is a pointer to the DIB bit values, as returned from
CreateDIBSection. ptSizeDP is the size of the bitmap, in device coordinates.
// Set the alpha values for each pixel in the cursor so that the cursor is
semi-transparent.
DWORD* lpdwPixel;
lpdwPixel = (DWORD*)lpBits;
DWORD dwBlack = 0x00000000;
DWORD dwWhite = 0x00FFFFFF;
for( int x = 0; x < ptSizeDP.x; x++ )
for( int y = 0; y < ptSizeDP.y; y++ )
{
// Clear the alpha bits (this will make all bits transparent).
*lpdwPixel &= 0x00FFFFFF;
//If pixel is black, set the alpha bit to opaque.
if( *lpdwPixel == dwBlack )
*lpdwPixel |= 0xFF000000;
//If pixel is white, set the alpha bits to 0x4F (semi-transparent)
else if( *lpdwPixel == dwWhite )
*lpdwPixel |= 0x4F000000;
lpdwPixel++;
}
//Create the icon info structure.
ICONINFO ii;
ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
ii.xHotspot = ptSizeDP.x / 2;
ii.yHotspot = ptSizeDP.y / 2;
ii.hbmMask = hMonoBitmap;
ii.hbmColor = hBitmap;
// Create the alpha cursor with the alpha DIB section.
hAlphaCursor = CreateIconIndirect( &ii );
SetCursor( hAlphaCursor );
I wonder, does this work correctly if you use the AND/XOR bitmaps without
setting the semi-transparent pixels? If it does, you can use dithering
instead of alpha...
shaginesh pk ,
2010-09-03 14:29:42 UTC
Permalink
Is there any other method for creating an cursor from bitmap or a string.(Transparent cursor)
Post by Justin Bozalina
I'm running VS 2005. The application I develop for uses a "shaping tool"
cursor at some points, replacing the cursor with a transparent bitmap. It
does this by creating a bitmap, testing the colors of the bitmap to set the
alpha values, then using CreateIconIndirect to create an HCURSOR, as seen
below.
This normally works correctly. However, we've observed that when both third
party and our own add-ons to the software create an OpenGL context for
on-screen and off-screen rendering, the cursor does not display as expected.
Instead of displaying the entire cursor bitmap, it won't display anything
larger than 61 pixels, in the x or y dimensions. Once the OpenGL context is
destroyed, it goes back to working as it should.
Also peculiar, when running OpenGL, the entire cursor bitmap WILL display
correctly if the transparency of the bitmap is not altered (the double for
loop is commented out). This occurs on every computer we run this on, ATI
and NVIDIA cards, otherwise I would think it was an OpenGL issue. Any ideas?
lpdwPixel is a pointer to the DIB bit values, as returned from
CreateDIBSection. ptSizeDP is the size of the bitmap, in device coordinates.
// Set the alpha values for each pixel in the cursor so that the cursor is
semi-transparent.
DWORD* lpdwPixel;
lpdwPixel = (DWORD*)lpBits;
DWORD dwBlack = 0x00000000;
DWORD dwWhite = 0x00FFFFFF;
for( int x = 0; x < ptSizeDP.x; x++ )
for( int y = 0; y < ptSizeDP.y; y++ )
{
// Clear the alpha bits (this will make all bits transparent).
*lpdwPixel &= 0x00FFFFFF;
//If pixel is black, set the alpha bit to opaque.
if( *lpdwPixel == dwBlack )
*lpdwPixel |= 0xFF000000;
//If pixel is white, set the alpha bits to 0x4F (semi-transparent)
else if( *lpdwPixel == dwWhite )
*lpdwPixel |= 0x4F000000;
lpdwPixel++;
}
//Create the icon info structure.
ICONINFO ii;
ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
ii.xHotspot = ptSizeDP.x / 2;
ii.yHotspot = ptSizeDP.y / 2;
ii.hbmMask = hMonoBitmap;
ii.hbmColor = hBitmap;
// Create the alpha cursor with the alpha DIB section.
hAlphaCursor = CreateIconIndirect( &ii );
SetCursor( hAlphaCursor );
Post by Alex Cohn
I wonder, does this work correctly if you use the AND/XOR bitmaps without
setting the semi-transparent pixels? If it does, you can use dithering
instead of alpha...
Post by Steve LaBar
No, if I set up a standard cursor using AND/XOR bitmaps, the cursor works
correctly as long as it is entirely opaque. As soon as I create the mask in
such a way as to have a transparent section of the cursor, even a single
pixel, I get the clipping problem again.
Here is some additional information Justin and I have discovered since. We
did test it on an ATI card and it worked correctly, so it appears to be just
with Nvidia cards (contrary to below). Also, if you turn-off cursor and
bitmap hardware acceleration in the Display applet, the problem goes away.
We currently believe this to be a problem with the Nvidia driver.
Wonder if anyone else has run into this problem.
Submitted via EggHeadCafe - Software Developer Portal of Choice
Scrolling in WPF Toolkit?s Column Chart
http://www.eggheadcafe.com/tutorials/aspnet/0939d60c-8e17-4a27-b898-1fc772d2d6f6/scrolling-in-wpf-toolkits-column-chart.aspx
Loading...