SDL_CreateCursor(3)
π SDL_CreateCursor β bestie edition π
okay so this is a page from the SDL3 FUNCTIONS manual, and yes it's literally called SDL_CreateCursor(3). sit down, grab a strawberry π, we're making a cursor out of raw bits.
β¨ NAME β¨
SDL_CreateCursor β make a cursor using the bitmap data and mask you hand it (in MSB format, we'll get to that).
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_mouse.h>
SDL_Cursor * SDL_CreateCursor(const Uint8 *data,
const Uint8 *mask,
int w, int h, int hot_x,
int hot_y);
π¦ DESCRIPTION π¦
okay bestie, first thing: mask has got to be in MSB (Most Significant Bit) format. no negotiating.
second thing: your cursor width, that's w, must be a multiple of 8 bits. the way that it just has to be. π
now the fun part β the cursor comes out in black and white, and it decides which is which based on this little chart right here:
data=0,mask=1: whitedata=1,mask=1: blackdata=0,mask=0: transparentdata=1,mask=0: inverted color if possible, black if not.
β οΈ real talk: cursors you make with this function must be freed with SDL_DestroyCursor(). do not ghost them. they will haunt you (leak). π
and if you're sitting there like "girl I want a color cursor" β or you wanna build your cursor out of an SDL_Surface β you want SDL_CreateColorCursor(). alternatively you can just hide the cursor and draw your own as part of your game's rendering, but heads up, that gets bound to the framerate. so. lowkey a tradeoff. π
also!! SDL_CreateSystemCursor() exists, and it hands you several readily-available system cursors to pick from. no bit-fiddling required, iconic behavior honestly. π
π FUNCTION PARAMETERS π
dataβ the color value for each pixel of the cursor.maskβ the mask value for each pixel of the cursor.wβ the width of the cursor.hβ the height of the cursor.hot_xβ the x-axis offset from the left of the cursor image to the mouse x position, in the range of0tow - 1.hot_yβ the y-axis offset from the top of the cursor image to the mouse y position, in the range of0toh - 1.
β RETURN VALUE β
on success you get a brand new cursor with all the parameters you specified. on failure you get NULL. π
if that happens, call SDL_GetError() for more info β she will tell you what went wrong, fr fr.
π§΅ THREAD SAFETY π§΅
main thread only, bestie. this function should only be called on the main thread. no side quests. π«Ά
π AVAILABILITY π
this function is available since SDL 3.2.0. periodt.
π SEE ALSO π
SDL_CreateAnimatedCursor(3)SDL_CreateColorCursor(3)SDL_CreateSystemCursor(3)SDL_DestroyCursor(3)SDL_SetCursor(3)
Simple Directmedia Layer wrote this one, this is SDL 3.4.18, and the page is SDL_CreateCursor(3). mwah, go make something cute πβ¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms