annotate test/testlines2.c @ 2895:9328f53a0ca2

indent
author Sam Lantinga <slouken@libsdl.org>
date Sat, 20 Dec 2008 23:10:20 +0000
parents e4bafaa29c65
children
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
2892
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
66 if (i == 0) {
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
67 SDL_RenderLine(0, 0, window_w, window_h);
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
68 SDL_RenderLine(0, window_h, window_w, 0);
2895
Sam Lantinga <slouken@libsdl.org>
parents: 2892
diff changeset
69 SDL_RenderLine(0, window_h / 2, window_w, window_h / 2);
Sam Lantinga <slouken@libsdl.org>
parents: 2892
diff changeset
70 SDL_RenderLine(window_w / 2, 0, window_w / 2, window_h);
2892
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
71 } else {
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
72 x1 = rand() % window_w;
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
73 x2 = rand() % window_w;
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
74 y1 = rand() % window_h;
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
75 y2 = rand() % window_h;
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
76 SDL_RenderLine(x1, y1, x2, y2);
e4bafaa29c65 Add a few test pattern lines
Sam Lantinga <slouken@libsdl.org>
parents: 2887
diff changeset
77 }
2887
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
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 /* Update the screen! */
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 SDL_RenderPresent();
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 }
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 int
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 main(int argc, char *argv[])
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 int i, done;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 SDL_Event event;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 Uint32 then, now, frames;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 /* Initialize parameters */
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 num_lines = NUM_LINES;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 /* Initialize test framework */
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 state = CommonCreateState(argv, SDL_INIT_VIDEO);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 if (!state) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 return 1;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 for (i = 1; i < argc;) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 int consumed;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 consumed = CommonArg(state, i);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 if (consumed == 0) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 consumed = -1;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 if (SDL_strcasecmp(argv[i], "--blend") == 0) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 if (argv[i + 1]) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 blendMode = SDL_BLENDMODE_NONE;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 consumed = 2;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 } 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
112 blendMode = SDL_BLENDMODE_MASK;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 consumed = 2;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 } 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
115 blendMode = SDL_BLENDMODE_BLEND;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 consumed = 2;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 } 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
118 blendMode = SDL_BLENDMODE_ADD;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 consumed = 2;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 } 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
121 blendMode = SDL_BLENDMODE_MOD;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 consumed = 2;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 cycle_color = SDL_TRUE;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 consumed = 1;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 cycle_alpha = SDL_TRUE;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 consumed = 1;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 } else if (SDL_isdigit(*argv[i])) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 num_lines = SDL_atoi(argv[i]);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 consumed = 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 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 if (consumed < 0) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 fprintf(stderr,
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 "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
139 argv[0], CommonUsage(state));
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 return 1;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 i += consumed;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 if (!CommonInit(state)) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 return 2;
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 /* Create the windows and initialize the renderers */
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 for (i = 0; i < state->num_windows; ++i) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 SDL_SelectRenderer(state->windows[i]);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 SDL_RenderFill(NULL);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 srand(time(NULL));
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 /* Main render loop */
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 frames = 0;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 then = SDL_GetTicks();
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 done = 0;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 while (!done) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 /* Check for events */
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 ++frames;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 while (SDL_PollEvent(&event)) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 CommonEvent(state, &event, &done);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 switch (event.type) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 case SDL_WINDOWEVENT:
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 switch (event.window.event) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 case SDL_WINDOWEVENT_EXPOSED:
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 SDL_SelectRenderer(event.window.windowID);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 SDL_RenderFill(NULL);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 break;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 break;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 default:
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 break;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 for (i = 0; i < state->num_windows; ++i) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 DrawLines(state->windows[i]);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
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
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 /* Print out some timing information */
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 now = SDL_GetTicks();
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 if (now > then) {
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 double fps = ((double) frames * 1000) / (now - then);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 printf("%2.2f frames per second\n", fps);
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 return 0;
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 }
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193
f8c0c5ef6d54 Added a test program for line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 /* vi: set ts=4 sw=4 expandtab: */