test/testdraw2.c
changeset 5147 ad50b3db78bd
parent 5140 e743b9c3f6d6
child 5184 d976b67150c5
     1.1 --- a/test/testdraw2.c	Tue Feb 01 19:15:42 2011 -0800
     1.2 +++ b/test/testdraw2.c	Tue Feb 01 19:19:43 2011 -0800
     1.3 @@ -19,7 +19,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 @@ -28,7 +28,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 @@ -53,18 +52,17 @@
    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  void
    1.37 -DrawLines(SDL_Window * window)
    1.38 +DrawLines(SDL_Window * window, SDL_Renderer * renderer)
    1.39  {
    1.40      int i;
    1.41      int x1, y1, x2, y2;
    1.42 @@ -73,7 +71,6 @@
    1.43      /* Query the sizes */
    1.44      SDL_GetWindowSize(window, &window_w, &window_h);
    1.45  
    1.46 -    SDL_SetRenderDrawBlendMode(blendMode);
    1.47      for (i = 0; i < num_objects; ++i) {
    1.48          /* Cycle the color and alpha, if desired */
    1.49          if (cycle_color) {
    1.50 @@ -98,27 +95,26 @@
    1.51                  cycle_direction = -cycle_direction;
    1.52              }
    1.53          }
    1.54 -        SDL_SetRenderDrawColor(255, (Uint8) current_color,
    1.55 +        SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
    1.56                                 (Uint8) current_color, (Uint8) current_alpha);
    1.57  
    1.58          if (i == 0) {
    1.59 -            SDL_RenderDrawLine(0, 0, window_w - 1, window_h - 1);
    1.60 -            SDL_RenderDrawLine(0, window_h - 1, window_w - 1, 0);
    1.61 -            SDL_RenderDrawLine(0, window_h / 2, window_w - 1, window_h / 2);
    1.62 -            SDL_RenderDrawLine(window_w / 2, 0, window_w / 2, window_h - 1);
    1.63 +            SDL_RenderDrawLine(renderer, 0, 0, window_w - 1, window_h - 1);
    1.64 +            SDL_RenderDrawLine(renderer, 0, window_h - 1, window_w - 1, 0);
    1.65 +            SDL_RenderDrawLine(renderer, 0, window_h / 2, window_w - 1, window_h / 2);
    1.66 +            SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1);
    1.67          } else {
    1.68              x1 = (rand() % (window_w*2)) - window_w;
    1.69              x2 = (rand() % (window_w*2)) - window_w;
    1.70              y1 = (rand() % (window_h*2)) - window_h;
    1.71              y2 = (rand() % (window_h*2)) - window_h;
    1.72 -            SDL_RenderDrawLine(x1, y1, x2, y2);
    1.73 +            SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
    1.74          }
    1.75      }
    1.76 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    1.77  }
    1.78  
    1.79  void
    1.80 -DrawRects(SDL_Window * window)
    1.81 +DrawRects(SDL_Window * window, SDL_Renderer * renderer)
    1.82  {
    1.83      int i;
    1.84      SDL_Rect rect;
    1.85 @@ -127,7 +123,6 @@
    1.86      /* Query the sizes */
    1.87      SDL_GetWindowSize(window, &window_w, &window_h);
    1.88  
    1.89 -    SDL_SetRenderDrawBlendMode(blendMode);
    1.90      for (i = 0; i < num_objects / 4; ++i) {
    1.91          /* Cycle the color and alpha, if desired */
    1.92          if (cycle_color) {
    1.93 @@ -152,16 +147,15 @@
    1.94                  cycle_direction = -cycle_direction;
    1.95              }
    1.96          }
    1.97 -        SDL_SetRenderDrawColor(255, (Uint8) current_color,
    1.98 +        SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
    1.99                                 (Uint8) current_color, (Uint8) current_alpha);
   1.100  
   1.101          rect.w = rand() % (window_h / 2);
   1.102          rect.h = rand() % (window_h / 2);
   1.103          rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2);
   1.104          rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2);
   1.105 -        SDL_RenderFillRect(&rect);
   1.106 +        SDL_RenderFillRect(renderer, &rect);
   1.107      }
   1.108 -    SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
   1.109  }
   1.110  
   1.111  int
   1.112 @@ -223,9 +217,10 @@
   1.113  
   1.114      /* Create the windows and initialize the renderers */
   1.115      for (i = 0; i < state->num_windows; ++i) {
   1.116 -        SDL_SelectRenderer(state->windows[i]);
   1.117 -        SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   1.118 -        SDL_RenderClear();
   1.119 +        SDL_Renderer *renderer = state->renderers[i];
   1.120 +        SDL_SetRenderDrawBlendMode(renderer, blendMode);
   1.121 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   1.122 +        SDL_RenderClear(renderer);
   1.123      }
   1.124  
   1.125      srand((unsigned int)time(NULL));
   1.126 @@ -239,30 +234,17 @@
   1.127          ++frames;
   1.128          while (SDL_PollEvent(&event)) {
   1.129              CommonEvent(state, &event, &done);
   1.130 -            switch (event.type) {
   1.131 -            case SDL_WINDOWEVENT:
   1.132 -                switch (event.window.event) {
   1.133 -                case SDL_WINDOWEVENT_EXPOSED:
   1.134 -                    SDL_SelectRenderer(SDL_GetWindowFromID(event.window.windowID));
   1.135 -                    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   1.136 -                    SDL_RenderClear();
   1.137 -                    break;
   1.138 -                }
   1.139 -                break;
   1.140 -            default:
   1.141 -                break;
   1.142 -            }
   1.143          }
   1.144          for (i = 0; i < state->num_windows; ++i) {
   1.145 -            SDL_SelectRenderer(state->windows[i]);
   1.146 -            SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   1.147 -            SDL_RenderClear();
   1.148 +            SDL_Renderer *renderer = state->renderers[i];
   1.149 +            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   1.150 +            SDL_RenderClear(renderer);
   1.151  
   1.152 -            DrawRects(state->windows[i]);
   1.153 -            DrawLines(state->windows[i]);
   1.154 -            DrawPoints(state->windows[i]);
   1.155 +            DrawRects(state->windows[i], renderer);
   1.156 +            DrawLines(state->windows[i], renderer);
   1.157 +            DrawPoints(state->windows[i], renderer);
   1.158  
   1.159 -            SDL_RenderPresent();
   1.160 +            SDL_RenderPresent(renderer);
   1.161          }
   1.162      }
   1.163