comparison test/testdraw2.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 65848493e08e
children 64ce267332c6
comparison
equal deleted inserted replaced
3595:b7c6828d4039 3596:f638ded38b8a
56 SDL_SetRenderDrawColor(255, (Uint8) current_color, 56 SDL_SetRenderDrawColor(255, (Uint8) current_color,
57 (Uint8) current_color, (Uint8) current_alpha); 57 (Uint8) current_color, (Uint8) current_alpha);
58 58
59 x = rand() % window_w; 59 x = rand() % window_w;
60 y = rand() % window_h; 60 y = rand() % window_h;
61 SDL_RenderPoint(x, y); 61 SDL_RenderDrawPoint(x, y);
62 } 62 }
63 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 63 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
64 } 64 }
65 65
66 void 66 void
100 } 100 }
101 SDL_SetRenderDrawColor(255, (Uint8) current_color, 101 SDL_SetRenderDrawColor(255, (Uint8) current_color,
102 (Uint8) current_color, (Uint8) current_alpha); 102 (Uint8) current_color, (Uint8) current_alpha);
103 103
104 if (i == 0) { 104 if (i == 0) {
105 SDL_RenderLine(0, 0, window_w - 1, window_h - 1); 105 SDL_RenderDrawLine(0, 0, window_w - 1, window_h - 1);
106 SDL_RenderLine(0, window_h - 1, window_w - 1, 0); 106 SDL_RenderDrawLine(0, window_h - 1, window_w - 1, 0);
107 SDL_RenderLine(0, window_h / 2, window_w - 1, window_h / 2); 107 SDL_RenderDrawLine(0, window_h / 2, window_w - 1, window_h / 2);
108 SDL_RenderLine(window_w / 2, 0, window_w / 2, window_h - 1); 108 SDL_RenderDrawLine(window_w / 2, 0, window_w / 2, window_h - 1);
109 } else { 109 } else {
110 x1 = (rand() % (window_w*2)) - window_w; 110 x1 = (rand() % (window_w*2)) - window_w;
111 x2 = (rand() % (window_w*2)) - window_w; 111 x2 = (rand() % (window_w*2)) - window_w;
112 y1 = (rand() % (window_h*2)) - window_h; 112 y1 = (rand() % (window_h*2)) - window_h;
113 y2 = (rand() % (window_h*2)) - window_h; 113 y2 = (rand() % (window_h*2)) - window_h;
114 SDL_RenderLine(x1, y1, x2, y2); 114 SDL_RenderDrawLine(x1, y1, x2, y2);
115 } 115 }
116 } 116 }
117 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 117 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
118 } 118 }
119 119
157 157
158 rect.w = rand() % (window_h / 2); 158 rect.w = rand() % (window_h / 2);
159 rect.h = rand() % (window_h / 2); 159 rect.h = rand() % (window_h / 2);
160 rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2); 160 rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2);
161 rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2); 161 rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2);
162 SDL_RenderRect(&rect); 162 SDL_RenderFillRect(&rect);
163 } 163 }
164 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); 164 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
165 } 165 }
166 166
167 int 167 int
229 229
230 /* Create the windows and initialize the renderers */ 230 /* Create the windows and initialize the renderers */
231 for (i = 0; i < state->num_windows; ++i) { 231 for (i = 0; i < state->num_windows; ++i) {
232 SDL_SelectRenderer(state->windows[i]); 232 SDL_SelectRenderer(state->windows[i]);
233 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); 233 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
234 SDL_RenderRect(NULL); 234 SDL_RenderClear();
235 } 235 }
236 236
237 srand(time(NULL)); 237 srand(time(NULL));
238 238
239 /* Main render loop */ 239 /* Main render loop */
249 case SDL_WINDOWEVENT: 249 case SDL_WINDOWEVENT:
250 switch (event.window.event) { 250 switch (event.window.event) {
251 case SDL_WINDOWEVENT_EXPOSED: 251 case SDL_WINDOWEVENT_EXPOSED:
252 SDL_SelectRenderer(event.window.windowID); 252 SDL_SelectRenderer(event.window.windowID);
253 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); 253 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
254 SDL_RenderRect(NULL); 254 SDL_RenderClear();
255 break; 255 break;
256 } 256 }
257 break; 257 break;
258 default: 258 default:
259 break; 259 break;
260 } 260 }
261 } 261 }
262 for (i = 0; i < state->num_windows; ++i) { 262 for (i = 0; i < state->num_windows; ++i) {
263 SDL_SelectRenderer(state->windows[i]); 263 SDL_SelectRenderer(state->windows[i]);
264 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); 264 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
265 SDL_RenderRect(NULL); 265 SDL_RenderClear();
266 266
267 DrawRects(state->windows[i]); 267 DrawRects(state->windows[i]);
268 DrawLines(state->windows[i]); 268 DrawLines(state->windows[i]);
269 DrawPoints(state->windows[i]); 269 DrawPoints(state->windows[i]);
270 270