test/testintersections.c
changeset 5147 ad50b3db78bd
parent 5140 e743b9c3f6d6
child 5184 d976b67150c5
     1.1 --- a/test/testintersections.c	Tue Feb 01 19:15:42 2011 -0800
     1.2 +++ b/test/testintersections.c	Tue Feb 01 19:19:43 2011 -0800
     1.3 @@ -20,7 +20,7 @@
     1.4  static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
     1.5  
     1.6  void
     1.7 -DrawPoints(SDL_Window * window)
     1.8 +DrawPoints(SDL_Window * window, SDL_Renderer * renderer)
     1.9  {
    1.10      int i;
    1.11      int x, y;
    1.12 @@ -29,7 +29,6 @@
    1.13      /* Query the sizes */
    1.14      SDL_GetWindowSize(window, &window_w, &window_h);
    1.15  
    1.16 -    SDL_SetRenderDrawBlendMode(blendMode);
    1.17      for (i = 0; i < num_objects * 4; ++i) {
    1.18          /* Cycle the color and alpha, if desired */
    1.19          if (cycle_color) {
    1.20 @@ -54,14 +53,13 @@
    1.21                  cycle_direction = -cycle_direction;
    1.22              }
    1.23          }
    1.24 -        SDL_SetRenderDrawColor(255, (Uint8) current_color,
    1.25 +        SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
    1.26                                 (Uint8) current_color, (Uint8) current_alpha);
    1.27  
    1.28          x = rand() % window_w;
    1.29          y = rand() % window_h;
    1.30 -        SDL_RenderDrawPoint(x, y);
    1.31 +        SDL_RenderDrawPoint(renderer, x, y);
    1.32      }
    1.33 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    1.34  }
    1.35  
    1.36  #define MAX_LINES 16
    1.37 @@ -86,7 +84,7 @@
    1.38  
    1.39  
    1.40  void
    1.41 -DrawLines(SDL_Window * window)
    1.42 +DrawLines(SDL_Window * window, SDL_Renderer * renderer)
    1.43  {
    1.44      int i;
    1.45      int x1, y1, x2, y2;
    1.46 @@ -95,20 +93,18 @@
    1.47      /* Query the sizes */
    1.48      SDL_GetWindowSize(window, &window_w, &window_h);
    1.49  
    1.50 -    SDL_SetRenderDrawBlendMode(blendMode);
    1.51      for (i = 0; i < num_lines; ++i) {
    1.52 -        SDL_SetRenderDrawColor(255, 255, 255, 255);
    1.53 +        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    1.54  
    1.55          if (i == -1) {
    1.56 -            SDL_RenderDrawLine(0, 0, window_w - 1, window_h - 1);
    1.57 -            SDL_RenderDrawLine(0, window_h - 1, window_w - 1, 0);
    1.58 -            SDL_RenderDrawLine(0, window_h / 2, window_w - 1, window_h / 2);
    1.59 -            SDL_RenderDrawLine(window_w / 2, 0, window_w / 2, window_h - 1);
    1.60 +            SDL_RenderDrawLine(renderer, 0, 0, window_w - 1, window_h - 1);
    1.61 +            SDL_RenderDrawLine(renderer, 0, window_h - 1, window_w - 1, 0);
    1.62 +            SDL_RenderDrawLine(renderer, 0, window_h / 2, window_w - 1, window_h / 2);
    1.63 +            SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1);
    1.64          } else {
    1.65 -            SDL_RenderDrawLine(lines[i].x, lines[i].y, lines[i].w, lines[i].h);
    1.66 +            SDL_RenderDrawLine(renderer, lines[i].x, lines[i].y, lines[i].w, lines[i].h);
    1.67          }
    1.68      }
    1.69 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    1.70  }
    1.71  
    1.72  #define MAX_RECTS 16
    1.73 @@ -139,7 +135,7 @@
    1.74  }
    1.75  
    1.76  static void
    1.77 -DrawRects(SDL_Window * window)
    1.78 +DrawRects(SDL_Window * window, SDL_Renderer * renderer)
    1.79  {
    1.80      int i;
    1.81      int window_w, window_h;
    1.82 @@ -147,24 +143,20 @@
    1.83      /* Query the sizes */
    1.84      SDL_GetWindowSize(window, &window_w, &window_h);
    1.85  
    1.86 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    1.87      for (i = 0; i < num_rects; ++i) {
    1.88 -        SDL_SetRenderDrawColor(255, 127, 0, 255);
    1.89 -        SDL_RenderFillRect(&rects[i]);
    1.90 +        SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
    1.91 +        SDL_RenderFillRect(renderer, &rects[i]);
    1.92      }
    1.93 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    1.94  }
    1.95  
    1.96  static void
    1.97 -DrawRectLineIntersections(SDL_Window * window)
    1.98 +DrawRectLineIntersections(SDL_Window * window, SDL_Renderer * renderer)
    1.99  {
   1.100      int i, j, window_w, window_h;
   1.101  
   1.102      /* Query the sizes */
   1.103      SDL_GetWindowSize(window, &window_w, &window_h);
   1.104  
   1.105 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
   1.106 -
   1.107      for (i = 0; i < num_rects; i++)
   1.108          for (j = 0; j < num_lines; j++) {
   1.109              int x1, y1, x2, y2;
   1.110 @@ -177,31 +169,25 @@
   1.111              y2 = lines[j].h;
   1.112  
   1.113              if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
   1.114 -                SDL_SetRenderDrawColor(0, 255, 55, 255);
   1.115 -                SDL_RenderDrawLine(x1, y1, x2, y2);
   1.116 +                SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255);
   1.117 +                SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
   1.118              }
   1.119          }
   1.120 -
   1.121 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
   1.122  }
   1.123  
   1.124  static void
   1.125 -DrawRectRectIntersections(SDL_Window * window)
   1.126 +DrawRectRectIntersections(SDL_Window * window, SDL_Renderer * renderer)
   1.127  {
   1.128      int i, j;
   1.129  
   1.130 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
   1.131 -
   1.132      for (i = 0; i < num_rects; i++)
   1.133          for (j = i + 1; j < num_rects; j++) {
   1.134              SDL_Rect r;
   1.135              if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
   1.136 -                SDL_SetRenderDrawColor(255, 200, 0, 255);
   1.137 -                SDL_RenderFillRect(&r);
   1.138 +                SDL_SetRenderDrawColor(renderer, 255, 200, 0, 255);
   1.139 +                SDL_RenderFillRect(renderer, &r);
   1.140              }
   1.141          }
   1.142 -
   1.143 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
   1.144  }
   1.145  
   1.146  int
   1.147 @@ -264,9 +250,10 @@
   1.148  
   1.149      /* Create the windows and initialize the renderers */
   1.150      for (i = 0; i < state->num_windows; ++i) {
   1.151 -        SDL_SelectRenderer(state->windows[i]);
   1.152 -        SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   1.153 -        SDL_RenderClear();
   1.154 +        SDL_Renderer *renderer = state->renderers[i];
   1.155 +        SDL_SetRenderDrawBlendMode(renderer, blendMode);
   1.156 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   1.157 +        SDL_RenderClear(renderer);
   1.158      }
   1.159  
   1.160      srand(time(NULL));
   1.161 @@ -311,31 +298,22 @@
   1.162                      break;
   1.163                  }
   1.164                  break;
   1.165 -            case SDL_WINDOWEVENT:
   1.166 -                switch (event.window.event) {
   1.167 -                case SDL_WINDOWEVENT_EXPOSED:
   1.168 -                    SDL_SelectRenderer(SDL_GetWindowFromID(event.window.windowID));
   1.169 -                    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   1.170 -                    SDL_RenderClear();
   1.171 -                    break;
   1.172 -                }
   1.173 -                break;
   1.174              default:
   1.175                  break;
   1.176              }
   1.177          }
   1.178          for (i = 0; i < state->num_windows; ++i) {
   1.179 -            SDL_SelectRenderer(state->windows[i]);
   1.180 -            SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   1.181 -            SDL_RenderClear();
   1.182 +            SDL_Renderer *renderer = state->renderers[i];
   1.183 +            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   1.184 +            SDL_RenderClear(renderer);
   1.185  
   1.186 -            DrawRects(state->windows[i]);
   1.187 -            DrawPoints(state->windows[i]);
   1.188 -            DrawRectRectIntersections(state->windows[i]);
   1.189 -            DrawLines(state->windows[i]);
   1.190 -            DrawRectLineIntersections(state->windows[i]);
   1.191 +            DrawRects(state->windows[i], renderer);
   1.192 +            DrawPoints(state->windows[i], renderer);
   1.193 +            DrawRectRectIntersections(state->windows[i], renderer);
   1.194 +            DrawLines(state->windows[i], renderer);
   1.195 +            DrawRectLineIntersections(state->windows[i], renderer);
   1.196  
   1.197 -            SDL_RenderPresent();
   1.198 +            SDL_RenderPresent(renderer);
   1.199          }
   1.200      }
   1.201