I’ve written a multi-player game where each person can choose to use the
mouse or keyboard.
The mouse pointer is hidden when it’s a keyboard player’s go and it’s also
important that the game returns the mouse pointer to its last position when
there are multiple mouse players.
The problem I have is that when my application redisplays the mouse pointer
using SDL_ShowCursor( SDL_ENABLE ) and then moves it using SDL_WarpMouse()
the pointer moves but the physical pointer isn’t redrawn.
The following example program demonstrates the issue well. The mouse
pointer is hidden and when it reappears it seems to be in the same place,
but if you ‘twitch’ the mouse slightly it jumps to its real position.
This is an issue in both Linux (1.2.0) and Windows (1.0.8), for both
full-screen and window when using the normal pointer. SDL seems to lock
and flush the events, but doesn’t work. I’d have to hack in a delay to
make it work, and I really don’t want to do that.
Help!
Ta.
- Deth. -
(P.S. Why does ‘gcc -Wconversion’ generate warnings with/without cast?)
====== Makefile ======
CC=gcc
CFLAGS=-Wall -O2 -pipe
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs)
default: test
test: test.c
$(CC) test.c $(CFLAGS) $(SDL_CFLAGS) $(SDL_LDFLAGS) -o test
====== test.c ======
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SYSTEM_ERROR 2
/* Main processing. */
int main( int argc, char *argv[] )
{
static SDL_Surface *Screen;
/* Access the SDL library. */
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
fprintf( stderr, "Unable to initialise SDL library,\n\t%s",
SDL_GetError() );
return SYSTEM_ERROR;
}
/* Ensure that SDL is closed when the program ends. */
if ( atexit( SDL_Quit ) )
{
perror( "atexit" );
fprintf( stderr, "Failed to register graphics shutdown handler." );
}
/* Open the graphics display. */
Screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_SWSURFACE );
if ( Screen == NULL )
{
fprintf( stderr, "Unable to set video mode,\n\t%s", SDL_GetError() );
return SYSTEM_ERROR;
}
/* Wait for 5 seconds. */
SDL_Delay( 5000 );
/* Hide the mouse pointer. */
(void) SDL_ShowCursor( SDL_DISABLE );
/* Wait for 5 seconds. */
SDL_Delay( 5000 );
/* Redisplay mouse pointer and then move it to the centre of the screen. */
(void) SDL_ShowCursor( SDL_ENABLE );
SDL_WarpMouse( (Uint16) SCREEN_WIDTH / 2, (Uint16) SCREEN_HEIGHT / 2 );
/* Wait for 5 seconds. */
SDL_Delay( 5000 );
/* Return successfully. */
return 0;
}