test/testsprite2.c
branchSDL-1.3
changeset 1724 6c63fc2bd986
parent 1712 931d111e737a
child 1725 98a3207ddde8
     1.1 --- a/test/testsprite2.c	Thu Jul 06 05:53:32 2006 +0000
     1.2 +++ b/test/testsprite2.c	Thu Jul 06 07:17:11 2006 +0000
     1.3 @@ -5,11 +5,12 @@
     1.4  
     1.5  #include "SDL.h"
     1.6  
     1.7 -#define NUM_WINDOWS 2
     1.8 +#define NUM_WINDOWS 4
     1.9  #define WINDOW_W    640
    1.10  #define WINDOW_H    480
    1.11  #define NUM_SPRITES	100
    1.12  #define MAX_SPEED 	1
    1.13 +#define BACKGROUND  0x00FFFFFF
    1.14  
    1.15  static int num_windows;
    1.16  static int num_sprites;
    1.17 @@ -85,8 +86,6 @@
    1.18  
    1.19      SDL_SelectRenderer(window);
    1.20  
    1.21 -    SDL_RenderFill(NULL, 0);
    1.22 -
    1.23      /* Query the sizes */
    1.24      SDL_GetWindowSize(window, &window_w, &window_h);
    1.25  
    1.26 @@ -94,6 +93,10 @@
    1.27      n = 0;
    1.28      for (i = 0; i < num_sprites; ++i) {
    1.29          position = &positions[i];
    1.30 +        SDL_RenderFill(position, BACKGROUND);
    1.31 +    }
    1.32 +    for (i = 0; i < num_sprites; ++i) {
    1.33 +        position = &positions[i];
    1.34          velocity = &velocities[i];
    1.35          position->x += velocity->x;
    1.36          if ((position->x < 0) || (position->x >= (window_w - sprite_w))) {
    1.37 @@ -168,7 +171,8 @@
    1.38  
    1.39          SDL_snprintf(title, sizeof(title), "testsprite %d", i + 1);
    1.40          windows[i] =
    1.41 -            SDL_CreateWindow(title, -1, -1, window_w, window_h,
    1.42 +            SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED,
    1.43 +                             SDL_WINDOWPOS_UNDEFINED, window_w, window_h,
    1.44                               SDL_WINDOW_SHOWN);
    1.45          if (!windows[i]) {
    1.46              fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
    1.47 @@ -179,6 +183,7 @@
    1.48              fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
    1.49              quit(2);
    1.50          }
    1.51 +        SDL_RenderFill(NULL, BACKGROUND);
    1.52      }
    1.53      if (LoadSprite("icon.bmp") < 0) {
    1.54          quit(2);
    1.55 @@ -214,6 +219,17 @@
    1.56          ++frames;
    1.57          while (SDL_PollEvent(&event)) {
    1.58              switch (event.type) {
    1.59 +            case SDL_WINDOWEVENT:
    1.60 +                switch (event.window.event) {
    1.61 +                case SDL_WINDOWEVENT_EXPOSED:
    1.62 +                    SDL_SelectRenderer(event.window.windowID);
    1.63 +                    SDL_RenderFill(NULL, BACKGROUND);
    1.64 +                    break;
    1.65 +                case SDL_WINDOWEVENT_CLOSE:
    1.66 +                    done = 1;
    1.67 +                    break;
    1.68 +                }
    1.69 +                break;
    1.70              case SDL_KEYDOWN:
    1.71                  /* Any keypress quits the app... */
    1.72              case SDL_QUIT: