Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- SDL_Surface *screen;
- Uint32 colors[SDL_MAXMOUSE];
- void put_square(int x, int y, int color)
- {
- SDL_Rect rect = { x - 5, y - 5, 10, 10};
- SDL_FillRect(screen, &rect, color);
- }
- static Uint32 timer(Uint32 interval, void * param)
- {
- SDL_Event event;
- event.type = SDL_VIDEOEXPOSE;
- SDL_PushEvent(&event);
- return interval;
- }
- int main(int argc, char **argv)
- {
- SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
- screen = SDL_SetVideoMode(0, 0, 32, SDL_HWSURFACE | SDL_FULLSCREEN);
- printf("Starting\n");
- colors[0] = SDL_MapRGB(screen->format, 255, 0, 0);
- colors[1] = SDL_MapRGB(screen->format, 0, 255, 0);
- colors[2] = SDL_MapRGB(screen->format, 0, 0, 255);
- colors[3] = SDL_MapRGB(screen->format, 255, 0, 255);
- colors[4] = SDL_MapRGB(screen->format, 255, 255, 0);
- colors[5] = SDL_MapRGB(screen->format, 0, 255, 255);
- SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
- SDL_Flip(screen);
- SDL_AddTimer(20, timer, NULL);
- SDL_Event event;
- while (SDL_WaitEvent(&event)) {
- switch (event.type) {
- case SDL_QUIT:
- goto quit;
- case SDL_MOUSEMOTION:
- put_square(event.motion.x, event.motion.y, colors[event.motion.which]);
- break;
- case SDL_VIDEOEXPOSE:
- SDL_Flip(screen);
- break;
- }
- }
- quit:
- printf("Quitting\n");
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement