annotate test/testdraw2.c @ 3334:61ea9005fddf

Use gcc's built-in dependency generation, thanks to Adam Strzelecki
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Oct 2009 03:38:01 +0000
parents 83c3a4b0e421
children 438ba87e9578
rev   line source
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 /* Simple program: draw as many random objects on the screen as possible */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 #include <stdlib.h>
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 #include <stdio.h>
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 #include <time.h>
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #include "common.h"
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #define NUM_OBJECTS 100
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 static CommonState *state;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 static int num_objects;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 static SDL_bool cycle_color;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 static SDL_bool cycle_alpha;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 static int cycle_direction = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 static int current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 static int current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 void
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 DrawPoints(SDL_WindowID window)
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 int i;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 int x, y;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 int window_w, window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /* Query the sizes */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 SDL_GetWindowSize(window, &window_w, &window_h);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 SDL_SetRenderDrawBlendMode(blendMode);
2902
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
32 for (i = 0; i < num_objects * 4; ++i) {
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 /* Cycle the color and alpha, if desired */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 if (cycle_color) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 current_color += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 if (current_color < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 current_color = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 if (current_color > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 if (cycle_alpha) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 current_alpha += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 if (current_alpha < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 current_alpha = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 if (current_alpha > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 SDL_SetRenderDrawColor(255, (Uint8) current_color,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 (Uint8) current_color, (Uint8) current_alpha);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 x = rand() % window_w;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 y = rand() % window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 SDL_RenderPoint(x, y);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 void
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 DrawLines(SDL_WindowID window)
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 int i;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 int x1, y1, x2, y2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 int window_w, window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 /* Query the sizes */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 SDL_GetWindowSize(window, &window_w, &window_h);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 SDL_SetRenderDrawBlendMode(blendMode);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 for (i = 0; i < num_objects; ++i) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 /* Cycle the color and alpha, if desired */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 if (cycle_color) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 current_color += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 if (current_color < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 current_color = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 if (current_color > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 if (cycle_alpha) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 current_alpha += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 if (current_alpha < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 current_alpha = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 if (current_alpha > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 SDL_SetRenderDrawColor(255, (Uint8) current_color,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 (Uint8) current_color, (Uint8) current_alpha);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 if (i == 0) {
2902
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
105 SDL_RenderLine(0, 0, window_w - 1, window_h - 1);
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
106 SDL_RenderLine(0, window_h - 1, window_w - 1, 0);
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
107 SDL_RenderLine(0, window_h / 2, window_w - 1, window_h / 2);
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
108 SDL_RenderLine(window_w / 2, 0, window_w / 2, window_h - 1);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 } else {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 x1 = rand() % window_w;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 x2 = rand() % window_w;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 y1 = rand() % window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 y2 = rand() % window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 SDL_RenderLine(x1, y1, x2, y2);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 void
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 DrawRects(SDL_WindowID window)
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 int i;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 SDL_Rect rect;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 int window_w, window_h;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 /* Query the sizes */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 SDL_GetWindowSize(window, &window_w, &window_h);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 SDL_SetRenderDrawBlendMode(blendMode);
2902
83c3a4b0e421 Fixed crash in testdraw2, added more points
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
131 for (i = 0; i < num_objects / 4; ++i) {
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 /* Cycle the color and alpha, if desired */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 if (cycle_color) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 current_color += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 if (current_color < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 current_color = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 if (current_color > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 current_color = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 if (cycle_alpha) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 current_alpha += cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 if (current_alpha < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 current_alpha = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 if (current_alpha > 255) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 current_alpha = 255;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 cycle_direction = -cycle_direction;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 SDL_SetRenderDrawColor(255, (Uint8) current_color,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 (Uint8) current_color, (Uint8) current_alpha);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 rect.w = rand() % (window_h / 2);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 rect.h = rand() % (window_h / 2);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 rect.x = (rand() % window_w) - (rect.w / 2);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 rect.y = (rand() % window_w) - (rect.h / 2);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 SDL_RenderFill(&rect);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 int
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 main(int argc, char *argv[])
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 int i, done;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 SDL_Event event;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 Uint32 then, now, frames;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 /* Initialize parameters */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 num_objects = NUM_OBJECTS;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 /* Initialize test framework */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 state = CommonCreateState(argv, SDL_INIT_VIDEO);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 if (!state) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 return 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 for (i = 1; i < argc;) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 int consumed;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 consumed = CommonArg(state, i);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 if (consumed == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 consumed = -1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 if (SDL_strcasecmp(argv[i], "--blend") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 if (argv[i + 1]) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 blendMode = SDL_BLENDMODE_NONE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 consumed = 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 blendMode = SDL_BLENDMODE_MASK;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 consumed = 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 blendMode = SDL_BLENDMODE_BLEND;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 consumed = 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 blendMode = SDL_BLENDMODE_ADD;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 consumed = 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 blendMode = SDL_BLENDMODE_MOD;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 consumed = 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 cycle_color = SDL_TRUE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 consumed = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 cycle_alpha = SDL_TRUE;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 consumed = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 } else if (SDL_isdigit(*argv[i])) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 num_objects = SDL_atoi(argv[i]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 consumed = 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 if (consumed < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 fprintf(stderr,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 "Usage: %s %s [--blend none|mask|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 argv[0], CommonUsage(state));
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 return 1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 i += consumed;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 if (!CommonInit(state)) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 return 2;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 /* Create the windows and initialize the renderers */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 for (i = 0; i < state->num_windows; ++i) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 SDL_SelectRenderer(state->windows[i]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 SDL_RenderFill(NULL);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 srand(time(NULL));
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 /* Main render loop */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 frames = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 then = SDL_GetTicks();
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 done = 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 while (!done) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 /* Check for events */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 ++frames;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 while (SDL_PollEvent(&event)) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 CommonEvent(state, &event, &done);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 switch (event.type) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 case SDL_WINDOWEVENT:
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 switch (event.window.event) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 case SDL_WINDOWEVENT_EXPOSED:
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 SDL_SelectRenderer(event.window.windowID);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 SDL_RenderFill(NULL);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 break;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 break;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 default:
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 break;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 for (i = 0; i < state->num_windows; ++i) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 SDL_SelectRenderer(state->windows[i]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 SDL_RenderFill(NULL);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 DrawRects(state->windows[i]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 DrawLines(state->windows[i]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 DrawPoints(state->windows[i]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 SDL_RenderPresent();
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 /* Print out some timing information */
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 now = SDL_GetTicks();
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 if (now > then) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 double fps = ((double) frames * 1000) / (now - then);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 printf("%2.2f frames per second\n", fps);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 return 0;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 /* vi: set ts=4 sw=4 expandtab: */