Mercurial > sdl-ios-xcode
annotate test/testlines2.c @ 2887:f8c0c5ef6d54
Added a test program for line drawing
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 20 Dec 2008 12:32:53 +0000 |
parents | |
children | e4bafaa29c65 |
rev | line source |
---|---|
2887
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 /* Simple program: draw as many random lines on the screen as possible */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 #include <stdlib.h> |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 #include <time.h> |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #include "common.h" |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #define NUM_LINES 100 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 static CommonState *state; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 static int num_lines; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 static SDL_bool cycle_color; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 static SDL_bool cycle_alpha; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 static int cycle_direction = 1; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 static int current_alpha = 255; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 static int current_color = 255; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 void |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 DrawLines(SDL_WindowID window) |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 int i, n; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 int x1, y1, x2, y2; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 int window_w, window_h; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 SDL_SelectRenderer(window); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 /* Query the sizes */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 SDL_GetWindowSize(window, &window_w, &window_h); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 /* Move the sprite, bounce at the wall, and draw */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 n = 0; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 SDL_RenderFill(NULL); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 SDL_SetRenderDrawBlendMode(blendMode); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 for (i = 0; i < num_lines; ++i) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 /* Cycle the color and alpha, if desired */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 if (cycle_color) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 current_color += cycle_direction; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 if (current_color < 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 current_color = 0; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 cycle_direction = -cycle_direction; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 if (current_color > 255) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 current_color = 255; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 cycle_direction = -cycle_direction; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 if (cycle_alpha) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 current_alpha += cycle_direction; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 if (current_alpha < 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 current_alpha = 0; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 cycle_direction = -cycle_direction; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 if (current_alpha > 255) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 current_alpha = 255; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 cycle_direction = -cycle_direction; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 SDL_SetRenderDrawColor(255, (Uint8) current_color, |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 (Uint8) current_color, (Uint8) current_alpha); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 x1 = rand() % window_w; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 x2 = rand() % window_w; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 y1 = rand() % window_h; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 y2 = rand() % window_h; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 SDL_RenderLine(x1, y1, x2, y2); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 /* Update the screen! */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 SDL_RenderPresent(); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 int |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 main(int argc, char *argv[]) |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 int i, done; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 SDL_Event event; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 Uint32 then, now, frames; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 /* Initialize parameters */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 num_lines = NUM_LINES; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 /* Initialize test framework */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 state = CommonCreateState(argv, SDL_INIT_VIDEO); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 if (!state) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 return 1; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 for (i = 1; i < argc;) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 int consumed; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 consumed = CommonArg(state, i); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 if (consumed == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 consumed = -1; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 if (SDL_strcasecmp(argv[i], "--blend") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 if (argv[i + 1]) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 if (SDL_strcasecmp(argv[i + 1], "none") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 blendMode = SDL_BLENDMODE_NONE; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 consumed = 2; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 blendMode = SDL_BLENDMODE_MASK; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 consumed = 2; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 blendMode = SDL_BLENDMODE_BLEND; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 consumed = 2; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 blendMode = SDL_BLENDMODE_ADD; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 consumed = 2; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 blendMode = SDL_BLENDMODE_MOD; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 consumed = 2; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 cycle_color = SDL_TRUE; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 consumed = 1; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 cycle_alpha = SDL_TRUE; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 consumed = 1; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 } else if (SDL_isdigit(*argv[i])) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 num_lines = SDL_atoi(argv[i]); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 consumed = 1; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 if (consumed < 0) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 fprintf(stderr, |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 "Usage: %s %s [--blend none|mask|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 argv[0], CommonUsage(state)); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 return 1; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 i += consumed; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 if (!CommonInit(state)) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 return 2; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 /* Create the windows and initialize the renderers */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 for (i = 0; i < state->num_windows; ++i) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 SDL_SelectRenderer(state->windows[i]); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 SDL_RenderFill(NULL); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 srand(time(NULL)); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 /* Main render loop */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 frames = 0; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 then = SDL_GetTicks(); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 done = 0; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 while (!done) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 /* Check for events */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 ++frames; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 while (SDL_PollEvent(&event)) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 CommonEvent(state, &event, &done); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 switch (event.type) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 case SDL_WINDOWEVENT: |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 switch (event.window.event) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 case SDL_WINDOWEVENT_EXPOSED: |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 SDL_SelectRenderer(event.window.windowID); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 SDL_RenderFill(NULL); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 break; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 break; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 default: |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 break; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 for (i = 0; i < state->num_windows; ++i) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 DrawLines(state->windows[i]); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 /* Print out some timing information */ |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 now = SDL_GetTicks(); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 if (now > then) { |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 double fps = ((double) frames * 1000) / (now - then); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 printf("%2.2f frames per second\n", fps); |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 return 0; |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 } |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 |
f8c0c5ef6d54
Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 /* vi: set ts=4 sw=4 expandtab: */ |