test/testspriteminimal.c
changeset 5147 ad50b3db78bd
parent 4969 d2247eb39fab
child 5158 b3ccd1947786
     1.1 --- a/test/testspriteminimal.c	Tue Feb 01 19:15:42 2011 -0800
     1.2 +++ b/test/testspriteminimal.c	Tue Feb 01 19:19:43 2011 -0800
     1.3 @@ -24,7 +24,7 @@
     1.4  }
     1.5  
     1.6  int
     1.7 -LoadSprite(char *file)
     1.8 +LoadSprite(char *file, SDL_Renderer *renderer)
     1.9  {
    1.10      SDL_Surface *temp;
    1.11  
    1.12 @@ -60,10 +60,10 @@
    1.13      }
    1.14  
    1.15      /* Create textures from the image */
    1.16 -    sprite = SDL_CreateTextureFromSurface(0, temp);
    1.17 +    sprite = SDL_CreateTextureFromSurface(renderer, 0, temp);
    1.18      if (!sprite) {
    1.19          SDL_SetColorKey(temp, 0, 0);
    1.20 -        sprite = SDL_CreateTextureFromSurface(0, temp);
    1.21 +        sprite = SDL_CreateTextureFromSurface(renderer, 0, temp);
    1.22      }
    1.23      if (!sprite) {
    1.24          fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
    1.25 @@ -77,7 +77,7 @@
    1.26  }
    1.27  
    1.28  void
    1.29 -MoveSprites(SDL_Window * window, SDL_Texture * sprite)
    1.30 +MoveSprites(SDL_Window * window, SDL_Renderer * renderer, SDL_Texture * sprite)
    1.31  {
    1.32      int i;
    1.33      int window_w = WINDOW_WIDTH;
    1.34 @@ -85,8 +85,8 @@
    1.35      SDL_Rect *position, *velocity;
    1.36  
    1.37      /* Draw a gray background */
    1.38 -    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
    1.39 -    SDL_RenderClear();
    1.40 +    SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.41 +    SDL_RenderClear(renderer);
    1.42  
    1.43      /* Move the sprite, bounce at the wall, and draw */
    1.44      for (i = 0; i < NUM_SPRITES; ++i) {
    1.45 @@ -104,17 +104,18 @@
    1.46          }
    1.47  
    1.48          /* Blit the sprite onto the screen */
    1.49 -        SDL_RenderCopy(sprite, NULL, position);
    1.50 +        SDL_RenderCopy(renderer, sprite, NULL, position);
    1.51      }
    1.52  
    1.53      /* Update the screen! */
    1.54 -    SDL_RenderPresent();
    1.55 +    SDL_RenderPresent(renderer);
    1.56  }
    1.57  
    1.58  int
    1.59  main(int argc, char *argv[])
    1.60  {
    1.61      SDL_Window *window;
    1.62 +    SDL_Renderer *renderer;
    1.63      int i, done;
    1.64      SDL_Event event;
    1.65  
    1.66 @@ -127,7 +128,12 @@
    1.67          quit(2);
    1.68      }
    1.69  
    1.70 -    if (LoadSprite("icon.bmp") < 0) {
    1.71 +    renderer = SDL_CreateRenderer(window, -1, 0);
    1.72 +    if (!renderer) {
    1.73 +        quit(2);
    1.74 +    }
    1.75 +
    1.76 +    if (LoadSprite("icon.bmp", renderer) < 0) {
    1.77          quit(2);
    1.78      }
    1.79  
    1.80 @@ -155,7 +161,7 @@
    1.81                  done = 1;
    1.82              }
    1.83          }
    1.84 -        MoveSprites(window, sprite);
    1.85 +        MoveSprites(window, renderer, sprite);
    1.86      }
    1.87  
    1.88      quit(0);