Change Mouse Cursor

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
LesPaul75
Posts: 35
Joined: Tue Jan 22, 2013 8:27 am

Change Mouse Cursor

Post by LesPaul75 »

I know this has to be an easy one, but I simply can't find anything helpful in the forum or elsewhere. I'm overlooking something.

I just want to change the mouse cursor to a custom image -- say a 32x32 PNG or whatever. I see that tutorial 24 does this, but it's very confusing to me. I don't need an animated cursor and I don't need a "bank" of cursors. I think the "bank" is what is causing me the most grief... and the difference between a "sprite" and an "icon" and a "cursor" and a "cursor sprite" is a little confusing.

I only want to change the primary arrow cursor. Is there a simple way to do this?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Change Mouse Cursor

Post by hendu »

If you don't want to change the hw cursor, you can always go sw.

ie: hide the OS cursor, draw your own using draw2DImage.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Change Mouse Cursor

Post by hybrid »

Example 6 has an example of how to render sw cursors, just as hendu suggests.
LesPaul75
Posts: 35
Joined: Tue Jan 22, 2013 8:27 am

Re: Change Mouse Cursor

Post by LesPaul75 »

Ok, but suppose I do want to change the HW cursor? I'm just looking to write simple function, e.g.:

Code: Select all

void change_mouse_cursor(const string &image_filename, irr::core::vector2di hotspot)
{
   // ... load the image into a sprite (or something?)
   // ... set the hotspot and whatever else
   // ... replace the main arrow cursor
}
I will also look into the SW cursor example, though, thanks.
LesPaul75
Posts: 35
Joined: Tue Jan 22, 2013 8:27 am

Re: Change Mouse Cursor

Post by LesPaul75 »

Any idea why my SW approach doesn't work? I took this from tutorial 6.

Code: Select all

    irr::video::ITexture* tex = driver->getTexture("E:\\Projects\\shmup-1\\test_cursor.png");
    driver->draw2DImage(tex, device->getCursorControl()->getPosition());
I have verified that "tex" is not null, which I guess means that the texture loaded properly. There is no error message, but nothing is drawn. I also verified that nothing is overlapping (in front of) the cursor, etc...

I also tried draw2DRectangle() and it doesn't draw anything, either.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Change Mouse Cursor

Post by Seven »

When are you rendering? Maybe paste a short test program
LesPaul75
Posts: 35
Joined: Tue Jan 22, 2013 8:27 am

Re: Change Mouse Cursor

Post by LesPaul75 »

Seven wrote:When are you rendering?
Yep, that was exactly the problem. I was doing it outside the begin/end scene calls.

Thanks for the help.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Change Mouse Cursor

Post by CuteAlien »

You don't get around creating a spritebank. But you can use the AddIconToSpriteBank function from the example if you want a non-animated cursor. It takes the name of your texture and the rectangle inside that texture where your cursor is. And ICursorControl::changeIcon can then be used to set the cursor you want to change to that new icon.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply