12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include <SDL.h>
- #include "savepng.h"
- int main( int argc, char* args[] )
- {
- SDL_Surface *screen;
- SDL_Surface *shot;
- Uint32 color;
- if (SDL_Init(SDL_INIT_VIDEO) < 0 || (screen = SDL_SetVideoMode(640, 480, 0, 0)) == 0)
- {
- fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
- exit(-1);
- }
-
- srand(time(NULL));
- color = SDL_MapRGB(screen->format,
- rand() % 255,
- rand() % 255,
- rand() % 255) | 0xFF000000;
- SDL_FillRect(screen, NULL, color);
-
- SDL_Delay(100);
- SDL_Flip(screen);
- SDL_Delay(1000);
-
- shot = SDL_PNGFormatAlpha(screen);
- SDL_SavePNG(shot, "screen.png");
- SDL_FreeSurface(shot);
- SDL_Quit();
- return 0;
- }
|