Sign in to follow this  
Charabis

SDL and Mouse Cursors

Recommended Posts

Is there a better method of making mouse cursors for SDL/OpenGL than a string of hex numbers shoved into two arrays, and then calling SDL_CreateCursor? I found it very time consuming, and the results weren't all that impressive for the time involved. Also, while it works fine on Windows, running it on Mac OSX gets the default cursor anyway, so I'm obviously looking for a cross-platform solution.

Share this post


Link to post
Share on other sites
Hmmm. Hadn't thought about turning a surface into a cursor, but it could work. Course I have to make the surface in the first place.

Exactly, Artum. I wanted a different cursor from the default.


Uint8 mask[] = {0x00, 0x80, 0x01, 0xc0, 0x03, 0xE0, 0x07, 0xF0, 0x0F, 0xF8, 0x1F, 0xFC, 0x3F, 0xFE, 0x7F, 0xFF };
Uint8 data[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
SDL_Cursor* cursor = SDL_CreateCursor(data, mask, 16, 8, 8, 0);
SDL_SetCursor (cursor);


is how I made my current one. Works fine on Windows under Code::Blocks, but Mac OS X just gives me the default cursor.

Share this post


Link to post
Share on other sites
Ah. Well then that's easy...


SDL_ShowCursor(0);//don't display the normal cursor

SDL_Surface *MouseImage=SDL_LoadBMP("MouseImage.bmp");//load up some BMP

int MouseX, MouseY;//for mouse coordinates

while(game is running)
{
SDL_GetMouseState(&MouseX, &MouseY);//get the coordinates of the mouse on the screen
DrawBMP(MouseImage, MouseX, MouseY);//draw the mouse on the screen
}

void DrawBMP(SDL_Surface *bmp, int x, int y)//drawing function
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_BlitSurface(bmp, NULL, Screen, &rect);
}



That should be all you need to have a different cursor. Disable drawing of the normal cursor, load up an image that you want to use instead, get the mouse coordinates, and finally draw the image you loaded where the mouse coordinates are.

Hope that helps.

-Artum.

Share this post


Link to post
Share on other sites
Indeed it might, but I'm too sleepy to try it right now. Fortunately, the info will still be there tomorrow [grin] Night!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this