annotate test/testscale.c @ 5282:8e421890cdb8

Fixed bug #1117 There's a new event that's always sent when the window changes size, and that event is what the renderers listen for to determine if they need to rebind their context.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 12 Feb 2011 19:02:14 -0800
parents a9eb73f21e3a
children
rev   line source
5245
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /* Simple program: Move N sprites around on the screen as fast as possible */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 #include <stdlib.h>
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 #include <stdio.h>
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 #include <time.h>
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 #include "SDL.h"
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #include "common.h"
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #define WINDOW_WIDTH 640
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 #define WINDOW_HEIGHT 480
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 static CommonState *state;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 typedef struct {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 SDL_Window *window;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 SDL_Renderer *renderer;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 SDL_Texture *background;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 SDL_Texture *sprite;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 SDL_Rect sprite_rect;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 int scale_direction;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 } DrawState;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 static void
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 quit(int rc)
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 CommonQuit(state);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 exit(rc);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 SDL_Texture *
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 SDL_Surface *temp;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 SDL_Texture *texture;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 /* Load the sprite image */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 temp = SDL_LoadBMP(file);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 if (temp == NULL) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 return NULL;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 /* Set transparent pixel as the pixel at (0,0) */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 if (transparent) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 if (temp->format->palette) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 } else {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 switch (temp->format->BitsPerPixel) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 case 15:
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 SDL_SetColorKey(temp, SDL_TRUE,
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 (*(Uint16 *) temp->pixels) & 0x00007FFF);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 break;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 case 16:
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 break;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 case 24:
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 SDL_SetColorKey(temp, SDL_TRUE,
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 break;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 case 32:
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 break;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 /* Create textures from the image */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 texture = SDL_CreateTextureFromSurface(renderer, temp);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 if (!texture) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 SDL_FreeSurface(temp);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 return NULL;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 SDL_FreeSurface(temp);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 /* We're ready to roll. :) */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 return texture;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 void
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 Draw(DrawState *s)
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 int w, h;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 SDL_Rect rect;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 SDL_GetWindowSize(s->window, &w, &h);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 /* Draw the background */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 SDL_RenderCopy(s->renderer, s->background, NULL, NULL);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 /* Scale and draw the sprite */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 s->sprite_rect.w += s->scale_direction;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 s->sprite_rect.h += s->scale_direction;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 if (s->scale_direction > 0) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 if (s->sprite_rect.w >= w || s->sprite_rect.h >= h) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 s->scale_direction = -1;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 } else {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 if (s->sprite_rect.w <= 1 || s->sprite_rect.h <= 1) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 s->scale_direction = 1;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 s->sprite_rect.x = (w - s->sprite_rect.w) / 2;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 s->sprite_rect.y = (h - s->sprite_rect.h) / 2;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 SDL_RenderCopy(s->renderer, s->sprite, NULL, &s->sprite_rect);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 /* Update the screen! */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 SDL_RenderPresent(s->renderer);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 int
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 main(int argc, char *argv[])
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 DrawState *drawstates;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 int i, done;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 SDL_Event event;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 int frames;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 Uint32 then, now;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 /* Initialize test framework */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 state = CommonCreateState(argv, SDL_INIT_VIDEO);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 if (!state) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 return 1;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 for (i = 1; i < argc;) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 int consumed;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 consumed = CommonArg(state, i);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 if (consumed == 0) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 fprintf(stderr, "Usage: %s %s\n", argv[0], CommonUsage(state));
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 return 1;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 i += consumed;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 if (!CommonInit(state)) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 quit(2);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 drawstates = SDL_stack_alloc(DrawState, state->num_windows);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 for (i = 0; i < state->num_windows; ++i) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 DrawState *drawstate = &drawstates[i];
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 drawstate->window = state->windows[i];
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 drawstate->renderer = state->renderers[i];
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 if (!drawstate->sprite || !drawstate->background) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 quit(2);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 SDL_QueryTexture(drawstate->sprite, NULL, NULL,
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 &drawstate->sprite_rect.w, &drawstate->sprite_rect.h);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 drawstate->scale_direction = 1;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 /* Main render loop */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 frames = 0;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 then = SDL_GetTicks();
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 done = 0;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 while (!done) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 /* Check for events */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 ++frames;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 while (SDL_PollEvent(&event)) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 CommonEvent(state, &event, &done);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 for (i = 0; i < state->num_windows; ++i) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 Draw(&drawstates[i]);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 /* Print out some timing information */
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 now = SDL_GetTicks();
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 if (now > then) {
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 double fps = ((double) frames * 1000) / (now - then);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 printf("%2.2f frames per second\n", fps);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 SDL_stack_free(drawstate);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 quit(0);
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 return 0;
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 }
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
a9eb73f21e3a Added a scaling test program
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 /* vi: set ts=4 sw=4 expandtab: */