comparison test/testintersections.c @ 3596:f638ded38b8a

Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color. Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine(). Added API for rectangle drawing (as opposed to filling) Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay. Optimized software line drawing quite a bit. Added support for Wu's anti-aliased line drawing, currently disabled by default.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 23 Dec 2009 01:55:00 +0000
parents 0267b8b1595c
children 64ce267332c6
comparison
equal deleted inserted replaced
3595:b7c6828d4039 3596:f638ded38b8a
57 SDL_SetRenderDrawColor(255, (Uint8) current_color, 57 SDL_SetRenderDrawColor(255, (Uint8) current_color,
58 (Uint8) current_color, (Uint8) current_alpha); 58 (Uint8) current_color, (Uint8) current_alpha);
59 59
60 x = rand() % window_w; 60 x = rand() % window_w;
61 y = rand() % window_h; 61 y = rand() % window_h;
62 SDL_RenderPoint(x, y); 62 SDL_RenderDrawPoint(x, y);
63 } 63 }
64 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 64 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
65 } 65 }
66 66
67 #define MAX_LINES 16 67 #define MAX_LINES 16
98 SDL_SetRenderDrawBlendMode(blendMode); 98 SDL_SetRenderDrawBlendMode(blendMode);
99 for (i = 0; i < num_lines; ++i) { 99 for (i = 0; i < num_lines; ++i) {
100 SDL_SetRenderDrawColor(255, 255, 255, 255); 100 SDL_SetRenderDrawColor(255, 255, 255, 255);
101 101
102 if (i == -1) { 102 if (i == -1) {
103 SDL_RenderLine(0, 0, window_w - 1, window_h - 1); 103 SDL_RenderDrawLine(0, 0, window_w - 1, window_h - 1);
104 SDL_RenderLine(0, window_h - 1, window_w - 1, 0); 104 SDL_RenderDrawLine(0, window_h - 1, window_w - 1, 0);
105 SDL_RenderLine(0, window_h / 2, window_w - 1, window_h / 2); 105 SDL_RenderDrawLine(0, window_h / 2, window_w - 1, window_h / 2);
106 SDL_RenderLine(window_w / 2, 0, window_w / 2, window_h - 1); 106 SDL_RenderDrawLine(window_w / 2, 0, window_w / 2, window_h - 1);
107 } else { 107 } else {
108 SDL_RenderLine(lines[i].x, lines[i].y, lines[i].w, lines[i].h); 108 SDL_RenderDrawLine(lines[i].x, lines[i].y, lines[i].w, lines[i].h);
109 } 109 }
110 } 110 }
111 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 111 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
112 } 112 }
113 113
148 SDL_GetWindowSize(window, &window_w, &window_h); 148 SDL_GetWindowSize(window, &window_w, &window_h);
149 149
150 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 150 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
151 for (i = 0; i < num_rects; ++i) { 151 for (i = 0; i < num_rects; ++i) {
152 SDL_SetRenderDrawColor(255, 127, 0, 255); 152 SDL_SetRenderDrawColor(255, 127, 0, 255);
153 SDL_RenderRect(&rects[i]); 153 SDL_RenderFillRect(&rects[i]);
154 } 154 }
155 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 155 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
156 } 156 }
157 157
158 static void 158 static void
176 x2 = lines[j].w; 176 x2 = lines[j].w;
177 y2 = lines[j].h; 177 y2 = lines[j].h;
178 178
179 if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) { 179 if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
180 SDL_SetRenderDrawColor(0, 255, 55, 255); 180 SDL_SetRenderDrawColor(0, 255, 55, 255);
181 SDL_RenderLine(x1, y1, x2, y2); 181 SDL_RenderDrawLine(x1, y1, x2, y2);
182 } 182 }
183 } 183 }
184 184
185 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 185 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
186 } 186 }
195 for (i = 0; i < num_rects; i++) 195 for (i = 0; i < num_rects; i++)
196 for (j = i + 1; j < num_rects; j++) { 196 for (j = i + 1; j < num_rects; j++) {
197 SDL_Rect r; 197 SDL_Rect r;
198 if (SDL_IntersectRect(&rects[i], &rects[j], &r)) { 198 if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
199 SDL_SetRenderDrawColor(255, 200, 0, 255); 199 SDL_SetRenderDrawColor(255, 200, 0, 255);
200 SDL_RenderRect(&r); 200 SDL_RenderFillRect(&r);
201 } 201 }
202 } 202 }
203 203
204 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 204 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
205 } 205 }
270 270
271 /* Create the windows and initialize the renderers */ 271 /* Create the windows and initialize the renderers */
272 for (i = 0; i < state->num_windows; ++i) { 272 for (i = 0; i < state->num_windows; ++i) {
273 SDL_SelectRenderer(state->windows[i]); 273 SDL_SelectRenderer(state->windows[i]);
274 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); 274 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
275 SDL_RenderRect(NULL); 275 SDL_RenderClear();
276 } 276 }
277 277
278 srand(time(NULL)); 278 srand(time(NULL));
279 279
280 /* Main render loop */ 280 /* Main render loop */
324 case SDL_WINDOWEVENT: 324 case SDL_WINDOWEVENT:
325 switch (event.window.event) { 325 switch (event.window.event) {
326 case SDL_WINDOWEVENT_EXPOSED: 326 case SDL_WINDOWEVENT_EXPOSED:
327 SDL_SelectRenderer(event.window.windowID); 327 SDL_SelectRenderer(event.window.windowID);
328 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); 328 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
329 SDL_RenderRect(NULL); 329 SDL_RenderClear();
330 break; 330 break;
331 } 331 }
332 break; 332 break;
333 default: 333 default:
334 break; 334 break;
335 } 335 }
336 } 336 }
337 for (i = 0; i < state->num_windows; ++i) { 337 for (i = 0; i < state->num_windows; ++i) {
338 SDL_SelectRenderer(state->windows[i]); 338 SDL_SelectRenderer(state->windows[i]);
339 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); 339 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
340 SDL_RenderRect(NULL); 340 SDL_RenderClear();
341 341
342 DrawRects(state->windows[i]); 342 DrawRects(state->windows[i]);
343 DrawPoints(state->windows[i]); 343 DrawPoints(state->windows[i]);
344 DrawRectRectIntersections(state->windows[i]); 344 DrawRectRectIntersections(state->windows[i]);
345 DrawLines(state->windows[i]); 345 DrawLines(state->windows[i]);