Mercurial > sdl-ios-xcode
annotate test/testwm2.c @ 1733:0b1070f2f94d SDL-1.3
Implemented gamma correction on Windows.
Added general code to restore the video mode and gamma when windows lose focus.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 09 Jul 2006 09:02:26 +0000 |
parents | 98a3207ddde8 |
children |
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 if (strcmp(argv[argc - 1], "-width") == 0) { |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 window_w = atoi(argv[argc]); |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 --argc; |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 } else if (strcmp(argv[argc - 1], "-height") == 0) { |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 window_h = atoi(argv[argc]); |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 --argc; |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 } else { |
1713
3e66ed1690e4
Whoops, forgot to indent
Sam Lantinga <slouken@libsdl.org>
parents:
1712
diff
changeset
|
47 fprintf(stderr, "Usage: %s [-width] [-height]\n", argv[0]); |
1712
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 quit(1); |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 } |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 } |
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 /* Create the windows */ |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows)); |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 if (!windows) { |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 fprintf(stderr, "Out of memory!\n"); |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 quit(2); |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 } |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 for (i = 0; i < num_windows; ++i) { |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 char title[32]; |
1719
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
60 int x, y; |
1712
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 SDL_snprintf(title, sizeof(title), "testwm %d", i + 1); |
1719
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
63 if (i == 0) { |
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
64 x = SDL_WINDOWPOS_CENTERED; |
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
65 y = SDL_WINDOWPOS_CENTERED; |
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
66 } else { |
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
67 x = SDL_WINDOWPOS_UNDEFINED; |
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
68 y = SDL_WINDOWPOS_UNDEFINED; |
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
69 } |
1712
931d111e737a
Started framework for Windows video driver
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 windows[i] = |
1719
5b9f50c957ed
You can now create multiple windows on Win32
Sam Lantinga <slouken@libsdl.org>
parents:
1713
diff
changeset
|
71 SDL_CreateWindow(title, x, y, window_w, window_h, |
1712
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: */ |