'SDL, change the cursor?

I'm using the SDL library, but what I'm trying to load a *.bmp file and display it as my new cursor, instead of the black and white cursor.

I think, that I most check the position of the mouse and draw the SDL_Surface at that position in a loop,

My code so far:

//Declare SDL_Surface pointers

SDL_Surface *cursor;
SDL_Surface *image;

SDL_ShowCursor( SDL_DISABLE ); //Standard cursor must be turned off

image = SDL_LoadBMP("mouse.bmp"); //Load my cursor

cursor = SDL_DisplayFormat(image); //Set

//Set the color as transparent
SDL_SetColorKey(cursor,SDL_SRCCOLORKEY|SDL_RLEACCEL,SDL_MapRGB(cursor->format,0x0,0x0,0x0));


Solution 1:[1]

Create and set a new SDL_Cursor should work.

SDL_Surface *surface = IMG_Load(filename);
SDL_Cursor *cursor = SDL_CreateColorCursor(surface);
SDL_SetCursor(cursor);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 成建文