12 void panic(char* aWhen
)
14 fprintf(stderr
, "SDL error: %s: %s\n", aWhen
, SDL_GetError());
19 int main(int argc
, char** argv
)
21 if(SDL_Init(SDL_INIT_VIDEO
) < 0 )
26 SDL_Rect
** modes
= SDL_ListModes(NULL
, SDL_FULLSCREEN
);
29 panic("No available video modes");
34 if(modes
!= (SDL_Rect
**) -1)
37 while(modes
[mode_count
] != NULL
)
39 printf("Mode %d: %d %d", mode_count
, modes
[mode_count
]->w
, modes
[mode_count
]->h
);
49 const Uint32 videoflags
= SDL_SWSURFACE
| SDL_ANYFORMAT
;
50 const int bpp
= 32; // full color
52 SDL_Surface
* bmp
= SDL_LoadBMP("ball.bmp");
55 panic("image not found");
57 SDL_Surface
* screen
= SDL_SetVideoMode(width
, height
, bpp
, videoflags
);
62 sourceRect
.w
= bmp
->w
;
63 sourceRect
.h
= bmp
->h
;
65 int then
= SDL_GetTicks();
69 targetRect
.x
= (screen
->w
- bmp
->w
) / 2;
70 targetRect
.y
= (screen
->h
- bmp
->h
) / 2;
72 targetRect
.w
= bmp
->w
;
73 targetRect
.h
= bmp
->h
;
83 while(SDL_PollEvent(&event
))
106 if(targetRect
.y
+ targetRect
.h
> screen
->h
)
109 targetRect
.y
= screen
->h
- targetRect
.h
;
125 if(targetRect
.x
+ targetRect
.w
> screen
->w
)
128 targetRect
.x
= screen
->w
- targetRect
.w
;
132 SDL_BlitSurface(bmp
, &sourceRect
, screen
, &targetRect
);
133 SDL_UpdateRect(screen
, 0, 0, screen
->w
, screen
->h
);
137 int now
= SDL_GetTicks();
140 SDL_FreeSurface(bmp
);
141 SDL_FreeSurface(screen
);