Added testnative to the Makefile and fixed building on Mac OS X
authorSam Lantinga <slouken@libsdl.org>
Sat, 07 Jan 2012 16:57:09 -0500
changeset 617542c40787f382
parent 6174 5f221b7a5952
child 6176 830fceed11c6
Added testnative to the Makefile and fixed building on Mac OS X
test/Makefile.in
test/common.c
test/testnative.c
     1.1 --- a/test/Makefile.in	Sat Jan 07 14:21:22 2012 -0500
     1.2 +++ b/test/Makefile.in	Sat Jan 07 16:57:09 2012 -0500
     1.3 @@ -39,6 +39,7 @@
     1.4  	testloadso$(EXE) \
     1.5  	testlock$(EXE) \
     1.6  	testmultiaudio$(EXE) \
     1.7 +	testnative$(EXE) \
     1.8  	testoverlay$(EXE) \
     1.9  	testoverlay2$(EXE) \
    1.10  	testplatform$(EXE) \
    1.11 @@ -162,6 +163,12 @@
    1.12  testlock$(EXE): $(srcdir)/testlock.c
    1.13  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.14  
    1.15 +testnative$(EXE): $(srcdir)/testnative.c \
    1.16 +			$(srcdir)/testnativecocoa.m \
    1.17 +			$(srcdir)/testnativew32.c \
    1.18 +			$(srcdir)/testnativex11.c
    1.19 +	$(CC) -o $@ $? $(CFLAGS) $(LIBS) -L/usr/X11/lib -lX11 -framework Cocoa
    1.20 +
    1.21  testoverlay2$(EXE): $(srcdir)/testoverlay2.c
    1.22  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.23  
     2.1 --- a/test/common.c	Sat Jan 07 14:21:22 2012 -0500
     2.2 +++ b/test/common.c	Sat Jan 07 16:57:09 2012 -0500
     2.3 @@ -359,6 +359,10 @@
     2.4          /* Print the usage message */
     2.5          return -1;
     2.6      }
     2.7 +    if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
     2.8 +	/* Debug flag sent by Xcode */
     2.9 +        return 2;
    2.10 +    }
    2.11      return 0;
    2.12  }
    2.13  
     3.1 --- a/test/testnative.c	Sat Jan 07 14:21:22 2012 -0500
     3.2 +++ b/test/testnative.c	Sat Jan 07 16:57:09 2012 -0500
     3.3 @@ -48,7 +48,7 @@
     3.4  }
     3.5  
     3.6  SDL_Texture *
     3.7 -LoadSprite(SDL_Window * window, char *file)
     3.8 +LoadSprite(SDL_Renderer *renderer, char *file)
     3.9  {
    3.10      SDL_Surface *temp;
    3.11      SDL_Texture *sprite;
    3.12 @@ -66,8 +66,7 @@
    3.13      }
    3.14  
    3.15      /* Create textures from the image */
    3.16 -    SDL_SelectRenderer(window);
    3.17 -    sprite = SDL_CreateTextureFromSurface(0, temp);
    3.18 +    sprite = SDL_CreateTextureFromSurface(renderer, temp);
    3.19      if (!sprite) {
    3.20          fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
    3.21          SDL_FreeSurface(temp);
    3.22 @@ -80,43 +79,42 @@
    3.23  }
    3.24  
    3.25  void
    3.26 -MoveSprites(SDL_Window * window, SDL_Texture * sprite)
    3.27 +MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
    3.28  {
    3.29 -    int i, n;
    3.30 -    int window_w, window_h;
    3.31      int sprite_w, sprite_h;
    3.32 +    int i;
    3.33 +    SDL_Rect viewport;
    3.34      SDL_Rect *position, *velocity;
    3.35  
    3.36 -    SDL_SelectRenderer(window);
    3.37 -
    3.38      /* Query the sizes */
    3.39 -    SDL_GetWindowSize(window, &window_w, &window_h);
    3.40 +    SDL_RenderGetViewport(renderer, &viewport);
    3.41      SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
    3.42  
    3.43 +    /* Draw a gray background */
    3.44 +    SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    3.45 +    SDL_RenderClear(renderer);
    3.46 +
    3.47      /* Move the sprite, bounce at the wall, and draw */
    3.48 -    n = 0;
    3.49 -    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
    3.50 -    SDL_RenderClear();
    3.51      for (i = 0; i < NUM_SPRITES; ++i) {
    3.52          position = &positions[i];
    3.53          velocity = &velocities[i];
    3.54          position->x += velocity->x;
    3.55 -        if ((position->x < 0) || (position->x >= (window_w - sprite_w))) {
    3.56 +        if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
    3.57              velocity->x = -velocity->x;
    3.58              position->x += velocity->x;
    3.59          }
    3.60          position->y += velocity->y;
    3.61 -        if ((position->y < 0) || (position->y >= (window_h - sprite_h))) {
    3.62 +        if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
    3.63              velocity->y = -velocity->y;
    3.64              position->y += velocity->y;
    3.65          }
    3.66  
    3.67          /* Blit the sprite onto the screen */
    3.68 -        SDL_RenderCopy(sprite, NULL, position);
    3.69 +        SDL_RenderCopy(renderer, sprite, NULL, position);
    3.70      }
    3.71  
    3.72      /* Update the screen! */
    3.73 -    SDL_RenderPresent();
    3.74 +    SDL_RenderPresent(renderer);
    3.75  }
    3.76  
    3.77  int
    3.78 @@ -125,12 +123,13 @@
    3.79      int i, done;
    3.80      const char *driver;
    3.81      SDL_Window *window;
    3.82 +    SDL_Renderer *renderer;
    3.83      SDL_Texture *sprite;
    3.84      int window_w, window_h;
    3.85      int sprite_w, sprite_h;
    3.86      SDL_Event event;
    3.87  
    3.88 -    if (SDL_VideoInit(NULL, 0) < 0) {
    3.89 +    if (SDL_VideoInit(NULL) < 0) {
    3.90          fprintf(stderr, "Couldn't initialize SDL video: %s\n",
    3.91                  SDL_GetError());
    3.92          exit(1);
    3.93 @@ -163,17 +162,17 @@
    3.94      SDL_SetWindowTitle(window, "SDL Native Window Test");
    3.95  
    3.96      /* Create the renderer */
    3.97 -    if (SDL_CreateRenderer(window, -1, 0) < 0) {
    3.98 +    renderer = SDL_CreateRenderer(window, -1, 0);
    3.99 +    if (!renderer) {
   3.100          fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
   3.101          quit(5);
   3.102      }
   3.103  
   3.104      /* Clear the window, load the sprite and go! */
   3.105 -    SDL_SelectRenderer(window);
   3.106 -    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   3.107 -    SDL_RenderClear();
   3.108 +    SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   3.109 +    SDL_RenderClear(renderer);
   3.110  
   3.111 -    sprite = LoadSprite(window, "icon.bmp");
   3.112 +    sprite = LoadSprite(renderer, "icon.bmp");
   3.113      if (!sprite) {
   3.114          quit(6);
   3.115      }
   3.116 @@ -210,9 +209,8 @@
   3.117              case SDL_WINDOWEVENT:
   3.118                  switch (event.window.event) {
   3.119                  case SDL_WINDOWEVENT_EXPOSED:
   3.120 -                    SDL_SelectRenderer(event.window.windowID);
   3.121 -                    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
   3.122 -                    SDL_RenderClear();
   3.123 +                    SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   3.124 +                    SDL_RenderClear(renderer);
   3.125                      break;
   3.126                  }
   3.127                  break;
   3.128 @@ -223,7 +221,7 @@
   3.129                  break;
   3.130              }
   3.131          }
   3.132 -        MoveSprites(window, sprite);
   3.133 +        MoveSprites(renderer, sprite);
   3.134      }
   3.135  
   3.136      quit(0);