comparison test/testsprite.c @ 587:f00ccf8d8edc

Added code to testsprite to detect tearing when flipping
author Sam Lantinga <slouken@libsdl.org>
date Sat, 01 Feb 2003 19:56:45 +0000
parents 21409a7a5fee
children 8bedd6d61642
comparison
equal deleted inserted replaced
586:abeb9f66c7f6 587:f00ccf8d8edc
5 #include <string.h> 5 #include <string.h>
6 #include <ctype.h> 6 #include <ctype.h>
7 #include <time.h> 7 #include <time.h>
8 8
9 #include "SDL.h" 9 #include "SDL.h"
10
11 #define DEBUG_FLIP 1
10 12
11 #define NUM_SPRITES 100 13 #define NUM_SPRITES 100
12 #define MAX_SPEED 1 14 #define MAX_SPEED 1
13 15
14 SDL_Surface *sprite; 16 SDL_Surface *sprite;
50 return(0); 52 return(0);
51 } 53 }
52 54
53 void MoveSprites(SDL_Surface *screen, Uint32 background) 55 void MoveSprites(SDL_Surface *screen, Uint32 background)
54 { 56 {
57 #if DEBUG_FLIP
58 static int t = 0;
59 #endif
60
55 int i, nupdates; 61 int i, nupdates;
56 SDL_Rect area, *position, *velocity; 62 SDL_Rect area, *position, *velocity;
57 63
58 nupdates = 0; 64 nupdates = 0;
59 /* Erase all the sprites if necessary */ 65 /* Erase all the sprites if necessary */
80 area = *position; 86 area = *position;
81 SDL_BlitSurface(sprite, NULL, screen, &area); 87 SDL_BlitSurface(sprite, NULL, screen, &area);
82 sprite_rects[nupdates++] = area; 88 sprite_rects[nupdates++] = area;
83 } 89 }
84 90
91 #if DEBUG_FLIP
92 {
93 Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0);
94 SDL_Rect r;
95 r.x = (sin((float)t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w-20);
96 r.y = 0;
97 r.w = 20;
98 r.h = screen->h;
99
100 SDL_FillRect (screen, &r, color);
101 t+=2;
102 }
103 #endif
104
85 /* Update the screen! */ 105 /* Update the screen! */
86 if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { 106 if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
87 SDL_Flip(screen); 107 SDL_Flip(screen);
88 } else { 108 } else {
89 SDL_UpdateRects(screen, nupdates, sprite_rects); 109 SDL_UpdateRects(screen, nupdates, sprite_rects);