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