SDL_PollEvent slow?

Hi!
A little while ago i started using SDL for my OpenGL based CRPG. So far i
have’nt done much but i already got into some truble…
THe problem i have is that when i use SDL_PollEvent in my game loop my
mousecursor moves slowly and with a delay (compared to the SDL pointer).
First i thought it might take time to draw the cursor but i changed it to be
a single point so that cant be the problem.

the game loop looks like this:

while(!quit){
if((SDL_PollEvent(&event)) != 0){
switch(event.type){
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_ESCAPE)
quit = true;
break;
case SDL_MOUSEMOTION:

		setcursorxy(somex,somey) //whatever
		break;	
	default:
	break;		
	}

}

//clear opengl stuff
//draw the cursor
//swapbuffers

} //end game loop

any body has any idea what might be the problem??
ANother problem i have is that when i set
SDL_ShowCurasor(0) the mouse jumps tp the lower right corner of the screen
and stays there…no matter what i do…what can i be?

anyway…thanx in advance

–Anders Folkesson

I think I know the prob here, but I’m new to SDL. :slight_smile:

During each iteration of your main loop there, you are only processing one
event. Your loop might run a few times before it gets to the mouse event.
Replace the if statement with something like this:

while (SDL_PollEvent (&event))

This will process all events every iteration, instead of just 1.

Anders Folkesson wrote:> Hi!

A little while ago i started using SDL for my OpenGL based CRPG. So far i
have’nt done much but i already got into some truble…
THe problem i have is that when i use SDL_PollEvent in my game loop my
mousecursor moves slowly and with a delay (compared to the SDL pointer).
First i thought it might take time to draw the cursor but i changed it to
be a single point so that cant be the problem.

the game loop looks like this:

while(!quit){
if((SDL_PollEvent(&event)) != 0){
switch(event.type){
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_ESCAPE)
quit = true;
break;
case SDL_MOUSEMOTION:

setcursorxy(somex,somey) //whatever
break;
default:
break;
}

}

//clear opengl stuff
//draw the cursor
//swapbuffers

} //end game loop

any body has any idea what might be the problem??
ANother problem i have is that when i set
SDL_ShowCurasor(0) the mouse jumps tp the lower right corner of the screen
and stays there…no matter what i do…what can i be?

anyway…thanx in advance

–Anders Folkesson

I have already tried that ine…without success unfortunately.
The problem with doing it that way as i see it is:

  1. if i use while instead of if in my game loop i will miss some screen
    updates…which leads to “jumps” with the mouse cursor

  2. i put a “cout” in the default section of the switch statement to see if i
    got any unhandeled events, but i dont.

can this have anything to do with the fact that i write the mouse cursor to
the backbuffert?? I am using OpenGL, so if anyone knows how to force writing
to the screenbuffer directly with dept_test turned on, please let me know
how…

anyway…thanks a bunch Mik :wink:

–Anders> I think I know the prob here, but I’m new to SDL. :slight_smile:

During each iteration of your main loop there, you are only processing one
event. Your loop might run a few times before it gets to the mouse event.
Replace the if statement with something like this:

while (SDL_PollEvent (&event))

This will process all events every iteration, instead of just 1.

Anders Folkesson wrote:

Hi!
A little while ago i started using SDL for my OpenGL based CRPG. So far i
have’nt done much but i already got into some truble…
THe problem i have is that when i use SDL_PollEvent in my game loop my
mousecursor moves slowly and with a delay (compared to the SDL pointer).
First i thought it might take time to draw the cursor but i changed it to
be a single point so that cant be the problem.

the game loop looks like this:

while(!quit){
if((SDL_PollEvent(&event)) != 0){
switch(event.type){
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_ESCAPE)
quit = true;
break;
case SDL_MOUSEMOTION:

setcursorxy(somex,somey) //whatever
break;
default:
break;
}

}

//clear opengl stuff
//draw the cursor
//swapbuffers

} //end game loop

any body has any idea what might be the problem??
ANother problem i have is that when i set
SDL_ShowCurasor(0) the mouse jumps tp the lower right corner of the
screen and stays there…no matter what i do…what can i be?

anyway…thanx in advance

–Anders Folkesson