comparison test/testwm2.c @ 1712:931d111e737a SDL-1.3

Started framework for Windows video driver
author Sam Lantinga <slouken@libsdl.org>
date Mon, 26 Jun 2006 13:56:56 +0000
parents
children 3e66ed1690e4
comparison
equal deleted inserted replaced
1711:865ba39fc96d 1712:931d111e737a
1 /* Simple program: Move N sprites around on the screen as fast as possible */
2
3 #include "SDL.h"
4
5 #define NUM_WINDOWS 2
6 #define WINDOW_W 640
7 #define WINDOW_H 480
8
9 static int num_windows;
10 static SDL_WindowID *windows;
11
12 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
13 static void
14 quit(int rc)
15 {
16 if (windows) {
17 SDL_free(windows);
18 }
19 SDL_Quit();
20 exit(rc);
21 }
22
23 int
24 main(int argc, char *argv[])
25 {
26 int window_w, window_h;
27 int i, done;
28 SDL_Event event;
29
30 /* Initialize SDL */
31 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
32 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
33 return (1);
34 }
35
36 num_windows = NUM_WINDOWS;
37 window_w = WINDOW_W;
38 window_h = WINDOW_H;
39 while (argc > 1) {
40 --argc;
41 if (strcmp(argv[argc - 1], "-width") == 0) {
42 window_w = atoi(argv[argc]);
43 --argc;
44 } else if (strcmp(argv[argc - 1], "-height") == 0) {
45 window_h = atoi(argv[argc]);
46 --argc;
47 } else {
48 fprintf(stderr,
49 "Usage: %s [-width] [-height]\n", argv[0]);
50 quit(1);
51 }
52 }
53
54 /* Set the desktop mode, we don't care what it is */
55 if (SDL_SetDisplayMode(NULL) < 0) {
56 fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError());
57 quit(2);
58 }
59
60 /* Create the windows */
61 windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows));
62 if (!windows) {
63 fprintf(stderr, "Out of memory!\n");
64 quit(2);
65 }
66 for (i = 0; i < num_windows; ++i) {
67 char title[32];
68
69 SDL_snprintf(title, sizeof(title), "testwm %d", i + 1);
70 windows[i] =
71 SDL_CreateWindow(title, -1, -1, window_w, window_h,
72 SDL_WINDOW_SHOWN);
73 if (!windows[i]) {
74 fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
75 quit(2);
76 }
77 }
78
79 /* Loop, blitting sprites and waiting for a keystroke */
80 done = 0;
81 while (!done) {
82 /* Check for events */
83 while (SDL_PollEvent(&event)) {
84 switch (event.type) {
85 case SDL_KEYDOWN:
86 /* Any keypress quits the app... */
87 case SDL_QUIT:
88 done = 1;
89 break;
90 default:
91 break;
92 }
93 }
94 }
95
96 quit(0);
97 }
98
99 /* vi: set ts=4 sw=4 expandtab: */