[SDL] Best way to display bitmaped mouse pointer

Carlos Alvarez citrouille at wanadoo.fr
Mon Aug 23 11:38:58 PDT 2004


Hello

I want an app that needs a colored mouse cursor. Seeing that the
SDL_SetCursor function doesn't provide colored pointer, I think that
the only way to do that is blitting to the screen a small bitmap (32x32 for example)
in each mousemotion event.
Now my problem is simple, I find my way to display the mouse cursor
very very slow, because I redraw whole screen before displaying
the mouse pointer...
like this :

SDL_Rect mousepos;
SDL_Event ev;
SDL_Surface *screen; //video's framebuffer surface
SDL_Surface *mouse; // mouse surface loaded from PNG file with pink
                    // colorkey

/*... video init stuff in 800x600x16 and double buffered ..*/

mouse = IMG_Load("cursor.png");
mouse = SDL_DisplayFormat(mouse);

while(loop)
{
  while(SDL_PollEvent(&ev))
  {
    switch(ev.type)
    {
      case SDL_MOUSEMOTION:
        mousepos.x = ev.motion.x;
        mousepos.y = ev.motion.y;
        break;
      case SDL_QUIT:
        loop=0;
    }
  }

  SDL_FillRect(screen, NULL, 0x0000);
  SDL_BlitSurface(mouse, NULL, screen, &mousepos);
  SDL_Flip(screen);
}


This small program, when heavily charged with graphics may be more slow,
because I need to redraw all.
Is there a best way to display a mouse pointer like this very quickly
?

thanks





More information about the SDL mailing list