Significantly delayed SDL video updates

If I remember correctly, I already met this problem, but I do not remember how I solved it. This is my program:

#include "SDL.h"

SDL_Surface *screen;
SDL_Event event;

int main(int argc,char *argv[])
{
    SDL_Init(SDL_INIT_VIDEO);
    atexit(SDL_Quit);
    screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
    int x = 10,y = 10;
    while (1)
    {
        while (SDL_PollEvent(&event))
        {
            if (event.type == SDL_QUIT)
                exit(0);
        }
        int mx,my;
        Uint8 mstate = SDL_GetMouseState(&mx,&my);
        if (mstate & SDL_BUTTON(1)) x = mx,y = my;
        SDL_FillRect(screen,NULL,0);
        *(Uint32*)((Uint8*)screen->pixels+screen->pitch*y+x*sizeof(Uint32)) = 0xFFFFFFFF;
        SDL_UpdateRect(screen,0,0,0,0);
    }
}

, . , , . . , . printf, - ( SDL_PollEvent (& event)). , SDL_SetVideoMode, . , , FPS . 320x200, 640x480 FPS, . , Ubuntu 11.10 Mesa. SDL - , ?

+3
1

(windows7), while (1) 1 .

, , , / Ubuntu 11.10 with Mesa graphics drivers.

, , .

:

  • / if (mstate & SDL_BUTTON(1))
  • SDL_UpdateRect(screen,x,y,1,1);
  • , .
  • SDL_Delay(10); while (1).
0

All Articles