annotate test/nds-test-progs/sprite2/source/testsprite2.c @ 2692:cd8978f47849 gsoc2008_nds

Minor cleanups in renderer.
author Darren Alton <dalton@stevens.edu>
date Sat, 16 Aug 2008 11:16:08 +0000
parents e9f27fe4f2a1
children c1c7cb1b5a47
rev   line source
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
1 /* Simple program: Move N sprites around on the screen as fast as possible */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
2
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
3 #include <stdlib.h>
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
4 #include <stdio.h>
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
5 #include <time.h>
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
6 #include <nds.h>
2692
cd8978f47849 Minor cleanups in renderer.
Darren Alton <dalton@stevens.edu>
parents: 2686
diff changeset
7 #include <fat.h>
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
8 #include "common.h"
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
9
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
10 #define NUM_SPRITES 100
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
11 #define MAX_SPEED 1
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
12
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
13 static CommonState *state;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
14 static int num_sprites;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
15 static SDL_TextureID *sprites;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
16 static SDL_bool cycle_color;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
17 static SDL_bool cycle_alpha;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
18 static int cycle_direction = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
19 static int current_alpha = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
20 static int current_color = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
21 static SDL_Rect *positions;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
22 static SDL_Rect *velocities;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
23 static int sprite_w, sprite_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
24 static SDL_TextureBlendMode blendMode = SDL_TEXTUREBLENDMODE_MASK;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
25 static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
26
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
27 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
28 static void
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
29 quit(int rc)
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
30 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
31 if (sprites) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
32 SDL_free(sprites);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
33 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
34 if (positions) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
35 SDL_free(positions);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
36 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
37 if (velocities) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
38 SDL_free(velocities);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
39 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
40 CommonQuit(state);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
41 exit(rc);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
42 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
43
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
44 int
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
45 LoadSprite(char *file)
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
46 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
47 int i;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
48 SDL_Surface *temp;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
49
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
50 /* Load the sprite image */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
51 temp = SDL_LoadBMP(file);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
52 if (temp == NULL) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
53 fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
54 return (-1);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
55 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
56 sprite_w = temp->w;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
57 sprite_h = temp->h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
58
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
59 /* Set transparent pixel as the pixel at (0,0) */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
60 if (temp->format->palette) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
61 SDL_SetColorKey(temp, SDL_SRCCOLORKEY, *(Uint8 *) temp->pixels);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
62 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
63
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
64 /* Create textures from the image */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
65 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
66 SDL_SelectRenderer(state->windows[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
67 sprites[i] = SDL_CreateTextureFromSurface(0, temp);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
68 if (!sprites[i]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
69 fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
70 SDL_FreeSurface(temp);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
71 return (-1);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
72 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
73 SDL_SetTextureBlendMode(sprites[i], blendMode);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
74 SDL_SetTextureScaleMode(sprites[i], scaleMode);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
75 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
76 SDL_FreeSurface(temp);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
77
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
78 /* We're ready to roll. :) */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
79 return (0);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
80 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
81
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
82 void
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
83 MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
84 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
85 int i, n;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
86 int window_w, window_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
87 SDL_Rect area, *position, *velocity;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
88
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
89 SDL_SelectRenderer(window);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
90
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
91 /* Query the sizes */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
92 SDL_GetWindowSize(window, &window_w, &window_h);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
93
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
94 /* Cycle the color and alpha, if desired */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
95 if (cycle_color) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
96 current_color += cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
97 if (current_color < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
98 current_color = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
99 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
100 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
101 if (current_color > 255) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
102 current_color = 255;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
103 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
104 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
105 SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
106 (Uint8) current_color);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
107 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
108 if (cycle_alpha) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
109 current_alpha += cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
110 if (current_alpha < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
111 current_alpha = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
112 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
113 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
114 if (current_alpha > 255) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
115 current_alpha = 255;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
116 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
117 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
118 SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
119 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
120
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
121 /* Move the sprite, bounce at the wall, and draw */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
122 n = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
123 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
124 for (i = 0; i < num_sprites; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
125 position = &positions[i];
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
126 velocity = &velocities[i];
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
127 position->x += velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
128 if ((position->x < 0) || (position->x >= (window_w - sprite_w))) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
129 velocity->x = -velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
130 position->x += velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
131 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
132 position->y += velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
133 if ((position->y < 0) || (position->y >= (window_h - sprite_w))) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
134 velocity->y = -velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
135 position->y += velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
136 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
137
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
138 /* Blit the sprite onto the screen */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
139 SDL_RenderCopy(sprite, NULL, position);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
140 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
141
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
142 /* Update the screen! */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
143 SDL_RenderPresent();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
144 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
145
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
146 int
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
147 main(int argc, char *argv[])
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
148 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
149 int i, done;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
150 SDL_Event event;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
151 Uint32 then, now, frames;
2692
cd8978f47849 Minor cleanups in renderer.
Darren Alton <dalton@stevens.edu>
parents: 2686
diff changeset
152 fatInitDefault();
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
153 /* Initialize parameters */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
154 num_sprites = NUM_SPRITES;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
155
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
156 /* Initialize test framework */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
157 state = CommonCreateState(argv, SDL_INIT_VIDEO);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
158 if (!state) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
159 return 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
160 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
161 for (i = 1; i < argc;) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
162 int consumed;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
163
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
164 consumed = CommonArg(state, i);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
165 if (consumed == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
166 consumed = -1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
167 if (SDL_strcasecmp(argv[i], "--blend") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
168 if (argv[i + 1]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
169 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
170 blendMode = SDL_TEXTUREBLENDMODE_NONE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
171 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
172 } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
173 blendMode = SDL_TEXTUREBLENDMODE_MASK;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
174 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
175 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
176 blendMode = SDL_TEXTUREBLENDMODE_BLEND;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
177 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
178 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
179 blendMode = SDL_TEXTUREBLENDMODE_ADD;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
180 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
181 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
182 blendMode = SDL_TEXTUREBLENDMODE_MOD;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
183 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
184 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
185 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
186 } else if (SDL_strcasecmp(argv[i], "--scale") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
187 if (argv[i + 1]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
188 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
189 scaleMode = SDL_TEXTURESCALEMODE_NONE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
190 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
191 } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
192 scaleMode = SDL_TEXTURESCALEMODE_FAST;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
193 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
194 } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
195 scaleMode = SDL_TEXTURESCALEMODE_SLOW;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
196 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
197 } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
198 scaleMode = SDL_TEXTURESCALEMODE_BEST;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
199 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
200 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
201 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
202 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
203 cycle_color = SDL_TRUE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
204 consumed = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
205 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
206 cycle_alpha = SDL_TRUE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
207 consumed = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
208 } else if (SDL_isdigit(*argv[i])) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
209 num_sprites = SDL_atoi(argv[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
210 consumed = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
211 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
212 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
213 if (consumed < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
214 fprintf(stderr,
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
215 "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n",
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
216 argv[0], CommonUsage(state));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
217 quit(1);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
218 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
219 i += consumed;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
220 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
221 if (!CommonInit(state)) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
222 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
223 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
224
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
225 /* Create the windows, initialize the renderers, and load the textures */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
226 sprites =
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
227 (SDL_TextureID *) SDL_malloc(state->num_windows * sizeof(*sprites));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
228 if (!sprites) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
229 fprintf(stderr, "Out of memory!\n");
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
230 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
231 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
232 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
233 SDL_SelectRenderer(state->windows[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
234 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
235 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
236 if (LoadSprite("icon.bmp") < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
237 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
238 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
239
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
240 /* Allocate memory for the sprite info */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
241 positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
242 velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
243 if (!positions || !velocities) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
244 fprintf(stderr, "Out of memory!\n");
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
245 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
246 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
247 srand(time(NULL));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
248 if (scaleMode != SDL_TEXTURESCALEMODE_NONE) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
249 sprite_w += sprite_w / 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
250 sprite_h += sprite_h / 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
251 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
252 for (i = 0; i < num_sprites; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
253 positions[i].x = rand() % (state->window_w - sprite_w);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
254 positions[i].y = rand() % (state->window_h - sprite_h);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
255 positions[i].w = sprite_w;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
256 positions[i].h = sprite_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
257 velocities[i].x = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
258 velocities[i].y = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
259 while (!velocities[i].x && !velocities[i].y) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
260 velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
261 velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
262 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
263 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
264
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
265 /* Main render loop */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
266 frames = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
267 then = SDL_GetTicks();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
268 done = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
269 while (!done) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
270 /* Check for events */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
271 ++frames;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
272 while (SDL_PollEvent(&event)) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
273 CommonEvent(state, &event, &done);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
274 switch (event.type) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
275 case SDL_WINDOWEVENT:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
276 switch (event.window.event) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
277 case SDL_WINDOWEVENT_EXPOSED:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
278 SDL_SelectRenderer(event.window.windowID);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
279 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
280 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
281 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
282 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
283 default:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
284 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
285 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
286 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
287 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
288 MoveSprites(state->windows[i], sprites[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
289 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
290 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
291
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
292 /* Print out some timing information */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
293 now = SDL_GetTicks();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
294 if (now > then) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
295 printf("%2.2f frames per second\n",
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
296 ((double) frames * 1000) / (now - then));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
297 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
298
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
299 quit(0);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
300 return 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
301 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
302
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
303 /* vi: set ts=4 sw=4 expandtab: */