comparison test/nds-test-progs/sprite2/source/testsprite2.c @ 2695:c04a266c277a gsoc2008_nds

More sprite-driven texture work in the render/video drivers.
author Darren Alton <dalton@stevens.edu>
date Sun, 17 Aug 2008 09:50:28 +0000
parents c1c7cb1b5a47
children e1da92da346c
comparison
equal deleted inserted replaced
2694:c1c7cb1b5a47 2695:c04a266c277a
4 #include <stdio.h> 4 #include <stdio.h>
5 #include <time.h> 5 #include <time.h>
6 #include <nds.h> 6 #include <nds.h>
7 #include <fat.h> 7 #include <fat.h>
8 #include "common.h" 8 #include "common.h"
9
10 #include "icon_bmp_bin.h"
9 11
10 #define NUM_SPRITES 10 12 #define NUM_SPRITES 10
11 #define MAX_SPEED 1 13 #define MAX_SPEED 1
12 14
13 static CommonState *state; 15 static CommonState *state;
77 79
78 /* We're ready to roll. :) */ 80 /* We're ready to roll. :) */
79 return (0); 81 return (0);
80 } 82 }
81 83
84 int LoadSprite2(const u8* ptr, int size) {
85 int i;
86 SDL_Rect r = {0,0,32,32};
87 for (i = 0; i < state->num_windows; ++i) {
88 SDL_SelectRenderer(state->windows[i]);
89 sprites[i] = SDL_CreateTexture(SDL_PIXELFORMAT_ABGR1555,
90 SDL_TEXTUREACCESS_STATIC, r.w, r.h);
91 if (!sprites[i]) {
92 fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
93 return -1;
94 }
95 SDL_UpdateTexture(sprites[i], &r, ptr, r.w*2);
96 SDL_SetTextureBlendMode(sprites[i], blendMode);
97 SDL_SetTextureScaleMode(sprites[i], scaleMode);
98 }
99 return 0;
100 }
101
82 void 102 void
83 MoveSprites(SDL_WindowID window, SDL_TextureID sprite) 103 MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
84 { 104 {
85 int i, n; 105 int i, n;
86 int window_w, window_h; 106 int window_w, window_h;
234 } 254 }
235 for (i = 0; i < state->num_windows; ++i) { 255 for (i = 0; i < state->num_windows; ++i) {
236 SDL_SelectRenderer(state->windows[i]); 256 SDL_SelectRenderer(state->windows[i]);
237 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL); 257 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
238 } 258 }
239 if (LoadSprite("icon.bmp") < 0) { 259 if (LoadSprite2(icon_bmp_bin, icon_bmp_bin_size) < 0) {
260 printf("errored.\n");
240 quit(2); 261 quit(2);
241 } 262 }
242 263
243 /* Allocate memory for the sprite info */ 264 /* Allocate memory for the sprite info */
244 positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); 265 positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));