test/testspriteminimal.c
changeset 5147 ad50b3db78bd
parent 4969 d2247eb39fab
child 5158 b3ccd1947786
--- a/test/testspriteminimal.c	Tue Feb 01 19:15:42 2011 -0800
+++ b/test/testspriteminimal.c	Tue Feb 01 19:19:43 2011 -0800
@@ -24,7 +24,7 @@
 }
 
 int
-LoadSprite(char *file)
+LoadSprite(char *file, SDL_Renderer *renderer)
 {
     SDL_Surface *temp;
 
@@ -60,10 +60,10 @@
     }
 
     /* Create textures from the image */
-    sprite = SDL_CreateTextureFromSurface(0, temp);
+    sprite = SDL_CreateTextureFromSurface(renderer, 0, temp);
     if (!sprite) {
         SDL_SetColorKey(temp, 0, 0);
-        sprite = SDL_CreateTextureFromSurface(0, temp);
+        sprite = SDL_CreateTextureFromSurface(renderer, 0, temp);
     }
     if (!sprite) {
         fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
@@ -77,7 +77,7 @@
 }
 
 void
-MoveSprites(SDL_Window * window, SDL_Texture * sprite)
+MoveSprites(SDL_Window * window, SDL_Renderer * renderer, SDL_Texture * sprite)
 {
     int i;
     int window_w = WINDOW_WIDTH;
@@ -85,8 +85,8 @@
     SDL_Rect *position, *velocity;
 
     /* Draw a gray background */
-    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
-    SDL_RenderClear();
+    SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
+    SDL_RenderClear(renderer);
 
     /* Move the sprite, bounce at the wall, and draw */
     for (i = 0; i < NUM_SPRITES; ++i) {
@@ -104,17 +104,18 @@
         }
 
         /* Blit the sprite onto the screen */
-        SDL_RenderCopy(sprite, NULL, position);
+        SDL_RenderCopy(renderer, sprite, NULL, position);
     }
 
     /* Update the screen! */
-    SDL_RenderPresent();
+    SDL_RenderPresent(renderer);
 }
 
 int
 main(int argc, char *argv[])
 {
     SDL_Window *window;
+    SDL_Renderer *renderer;
     int i, done;
     SDL_Event event;
 
@@ -127,7 +128,12 @@
         quit(2);
     }
 
-    if (LoadSprite("icon.bmp") < 0) {
+    renderer = SDL_CreateRenderer(window, -1, 0);
+    if (!renderer) {
+        quit(2);
+    }
+
+    if (LoadSprite("icon.bmp", renderer) < 0) {
         quit(2);
     }
 
@@ -155,7 +161,7 @@
                 done = 1;
             }
         }
-        MoveSprites(window, sprite);
+        MoveSprites(window, renderer, sprite);
     }
 
     quit(0);