• Advertisement
Sign in to follow this  

Alpha blended cursors?

This topic is 4106 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 working on trying to get alpha blended cursors working. In this time, I've pretty much convinced myself that the Direct3D cursor stuff really doesn't work very well at all (e.g. SetCursorProperties(), etc). According to the documentation, SetCursorProperties() doesn't support alpha blended cursors. Now I have been able to get them to work, but only by creating using the Win32 API CreateIconIndirect using a 32bpp HBITMAP with alpha info to create the cursor. Shouldn't there be a more correct way? Here's some code I just threw together to demonstrate what I'm doing (it's in C# with MDX, but you'll get the point). The only reason I'm using a DX surface is because its the easiest way to load the 32bpp bitmap, since Image.Load doesn't load the alpha channel.
            Bitmap mono = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format1bppIndexed);

            Bitmap bm = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            using ( Stream s = new FileStream("..\\..\\data\\cursor.bmp", FileMode.Open, FileAccess.Read) )
            {
                using ( Surface surf = Surface.FromStream(_device, s, Pool.Scratch) )
                {

                    using (GraphicsStream gs = surf.LockRectangle(LockFlags.None))
                    {
                        uint* data = (uint*)gs.InternalDataPointer;
                        for (int x = 0; x < 32; ++x)
                        {
                            for (int y = 0; y < 32; ++y)
                            {
                                uint z = *data++;
                                if (z == 0xffffffff)
                                    z = 0;
                                bm.SetPixel(x, y, Color.FromArgb((int)z));
                            }
                        }
                    }

                }

            }



            ICONINFO ii;
            ii.fIcon = false;
            ii.xHotspot = 16;
            ii.yHotspot = 16;
            ii.hbmColor = bm.GetHbitmap();
            ii.hbmMask = mono.GetHbitmap();

            IntPtr hIcon = CreateIconIndirect( ref ii);

            Cursor c = new Cursor(hIcon);

            _window.Cursor = c;

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Evil Steve
Is there any reason you don't just render a textured quad at the current cursor location?


If you do this, you're limited by framerate.

While I was working at SOE on this particular MMO, I'm not going to name names... but if you've played any big sci-fi MMOs you've probably played it, there were some cases where the frame rate could drop into the sub 10 FPS range (of course this could be expected with any MMO). At that point, it becomes extremely annoying when your cursor is running at the frame rate.

Fortunately, in that game it was possible to switch to a hardware cursor.

The difference is that game does not have an alpha blended cursor requirement.



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement