Very Simple program, for drawing on screen (like with pen in Paint)
I'm using SDL 1.2. Only events I'm proccesing are mouse motion, mouse left click and quiting program. My problem is that SDL_MOUSEMOTION events are 'skipped' when I'm moving mouse fast (when I say fast I mean faster than 1 pixel/second)
Why this happens?
screen shots:
http://postimg.org/image/gcb87v9zr/
http://postimg.org/image/i5e4w6v6f/
#include <SDL/SDL.h>
SDL_Event event;
SDL_Surface* screen;
bool clicked = false;
Uint32 whiteColor;
int W = 200; // screen width
int H = 200; // screen height
Uint32* screenPixels;
bool handleInput();
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(W,H,32,SDL_SWSURFACE);
whiteColor = SDL_MapRGB(screen->format,255,255,255);
screenPixels = (Uint32*) screen->pixels;
while(handleInput())
{
}
SDL_Quit();
return 0;
}
bool handleInput()
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:{
return false;
break;
}
case SDL_MOUSEBUTTONDOWN:{
clicked = true;
break;
}
case SDL_MOUSEBUTTONUP:{
clicked = false;
break;
}
case SDL_MOUSEMOTION:{
if(clicked)
{
int P_x = event.motion.x;
int P_y = event.motion.y;
screenPixels[P_y * W + P_x] = whiteColor;
SDL_Flip(screen);
}
break;
}
}
}
return true;
}
It is because you
SDL_Flipfor all your screen, it takes too many time.Better call
SDL_Flipin another thread (usingstd::async, for example).Or you may update not the all surface, but only the part which is changed color to white.