//g++ test.cpp -o test -lSDL -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT #include #include "SDL/SDL.h" void ShowBMP(SDL_Surface *image, SDL_Surface *screen, int x, int y) { SDL_Rect dest; /* Load the BMP file into a surface */ /* Blit onto the screen surface. The surfaces should not be locked at this point. */ dest.x = x; dest.y = y; dest.w = image->w; dest.h = image->h; SDL_BlitSurface(image, NULL, screen, &dest); /* Update the changed portion of the screen */ SDL_UpdateRects(screen, 1, &dest); } main(int argc, char *argv[]) { if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_Surface *screen; screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); if ( screen == NULL ) { fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError()); exit(1); } SDL_Event event; int x = 0; int y = 0; int speedX = 10; int speedY = 10; SDL_Surface *image1; SDL_Surface *image2; image1 = SDL_LoadBMP("screen.bmp"); image2 = SDL_LoadBMP("ayb.bmp"); SDL_DisplayFormat(image1); SDL_DisplayFormat(image2); while( true ) { SDL_Event event; SDL_PumpEvents(); SDL_PollEvent(&event); if ( event.type == SDL_QUIT ) { exit(0); } ShowBMP(image1, screen, 0,0); ShowBMP(image2, screen, x,y); SDL_Flip(screen); SDL_Delay(50); if ( x < 0 || x > 590) speedX = -speedX; if ( y < 0 || y > 430) speedY = -speedY; x += speedX; y += speedY; } exit(0); }