void loop() { SDL_Event event; /* Check for events */ while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN) { done = 1; } } MoveSprites(renderer, sprite); #ifdef __EMSCRIPTEN__ if (done) { emscripten_cancel_main_loop(); } #endif }
int main(int argc, char *argv[]) { SDL_Window *window; SDL_Renderer *renderer; int i, done; SDL_Event event; if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) { quit(2); } if (LoadSprite("icon.bmp", renderer) < 0) { quit(2); } /* Initialize the sprite positions */ srand(time(NULL)); for (i = 0; i < NUM_SPRITES; ++i) { positions[i].x = rand() % (WINDOW_WIDTH - sprite_w); positions[i].y = rand() % (WINDOW_HEIGHT - sprite_h); positions[i].w = sprite_w; positions[i].h = sprite_h; velocities[i].x = 0; velocities[i].y = 0; while (!velocities[i].x && !velocities[i].y) { velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; } } /* Main render loop */ done = 0; while (!done) { /* Check for events */ while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN) { done = 1; } } MoveSprites(window, renderer, sprite); } quit(0); }
int main() { InitGraphics(); giftable.packet_count = GIF_PACKET_MAX; giftable.packet = &packets[0]; InitSprites(); while(1) { GsGifPacketsClear(&giftable); // clear the area that we are going to put the sprites/triangles/.... MoveSprites(); DrawSprites(&giftable); //add stuff to the packet area GsDrawSync(0); GsVSync(0); GsClearDrawEnv1(&draw_env); // clear the draw environment before we draw stuff on it GsGifPacketsExecute(&giftable, 1); // set to '1' becuse we want to wait for drawing to finish. if we dont wait we will write on packets that is currently writing to the gif } return 0; }
void loop() { int i; SDL_Event event; /* Check for events */ while (SDL_PollEvent(&event)) { SDLTest_CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { if (state->windows[i] == NULL) continue; MoveSprites(state->renderers[i], sprites[i]); } #ifdef __EMSCRIPTEN__ if (done) { emscripten_cancel_main_loop(); } #endif }
int main(int argc, char *argv[]) { SDL_Surface *screen; Uint8 *mem; int width, height; Uint8 video_bpp; Uint32 videoflags; Uint32 background; int i, done; SDL_Event event; Uint32 then, now, frames; /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); exit(1); } atexit(SDL_Quit); numsprites = NUM_SPRITES; videoflags = SDL_SWSURFACE|SDL_ANYFORMAT; width = 640; height = 480; video_bpp = 8; while ( argc > 1 ) { --argc; if ( strcmp(argv[argc-1], "-width") == 0 ) { width = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-height") == 0 ) { height = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-bpp") == 0 ) { video_bpp = atoi(argv[argc]); videoflags &= ~SDL_ANYFORMAT; --argc; } else if ( strcmp(argv[argc], "-fast") == 0 ) { videoflags = FastestFlags(videoflags); } else if ( strcmp(argv[argc], "-hw") == 0 ) { videoflags ^= SDL_HWSURFACE; } else if ( strcmp(argv[argc], "-flip") == 0 ) { videoflags ^= SDL_DOUBLEBUF; } else if ( strcmp(argv[argc], "-fullscreen") == 0 ) { videoflags ^= SDL_FULLSCREEN; } else if ( isdigit(argv[argc][0]) ) { numsprites = atoi(argv[argc]); } else { fprintf(stderr, "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n", argv[0]); exit(1); } } /* Set video mode */ screen = SDL_SetVideoMode(width, height, video_bpp, videoflags); if ( ! screen ) { fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", width, height, SDL_GetError()); exit(2); } /* Load the sprite */ if ( LoadSprite(screen, "icon.bmp") < 0 ) { exit(1); } /* Allocate memory for the sprite info */ mem = (Uint8 *)malloc(4*sizeof(SDL_Rect)*numsprites); if ( mem == NULL ) { SDL_FreeSurface(sprite); fprintf(stderr, "Out of memory!\n"); exit(2); } sprite_rects = (SDL_Rect *)mem; positions = sprite_rects; sprite_rects += numsprites; velocities = sprite_rects; sprite_rects += numsprites; srand(time(NULL)); for ( i=0; i<numsprites; ++i ) { positions[i].x = rand()%screen->w; positions[i].y = rand()%screen->h; positions[i].w = sprite->w; positions[i].h = sprite->h; velocities[i].x = 0; velocities[i].y = 0; while ( ! velocities[i].x && ! velocities[i].y ) { velocities[i].x = (rand()%(MAX_SPEED*2+1))-MAX_SPEED; velocities[i].y = (rand()%(MAX_SPEED*2+1))-MAX_SPEED; } } background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); /* Print out information about our surfaces */ printf("Screen is at %d bits per pixel\n",screen->format->BitsPerPixel); if ( (screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { printf("Screen is in video memory\n"); } else { printf("Screen is in system memory\n"); } if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { printf("Screen has double-buffering enabled\n"); } if ( (sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { printf("Sprite is in video memory\n"); } else { printf("Sprite is in system memory\n"); } /* Run a sample blit to trigger blit acceleration */ { SDL_Rect dst; dst.x = 0; dst.y = 0; dst.w = sprite->w; dst.h = sprite->h; SDL_BlitSurface(sprite, NULL, screen, &dst); SDL_FillRect(screen, &dst, background); } if ( (sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) { printf("Sprite blit uses hardware acceleration\n"); } if ( (sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { printf("Sprite blit uses RLE acceleration\n"); } /* Loop, blitting sprites and waiting for a keystroke */ frames = 0; then = SDL_GetTicks(); done = 0; sprites_visible = 0; while ( !done ) { /* Check for events */ ++frames; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: /* Any keypress quits the app... */ case SDL_QUIT: done = 1; break; default: break; } } MoveSprites(screen, background); } SDL_FreeSurface(sprite); free(mem); /* Print out some timing information */ now = SDL_GetTicks(); if ( now > then ) { printf("%2.2f frames per second\n", ((double)frames*1000)/(now-then)); } return(0); }
int main(int argc, char *argv[]) { int i, done; const char *driver; SDL_Window *window; SDL_Texture *sprite; int window_w, window_h; int sprite_w, sprite_h; SDL_Event event; if (SDL_VideoInit(NULL, 0) < 0) { fprintf(stderr, "Couldn't initialize SDL video: %s\n", SDL_GetError()); exit(1); } driver = SDL_GetCurrentVideoDriver(); /* Find a native window driver and create a native window */ for (i = 0; factories[i]; ++i) { if (SDL_strcmp(driver, factories[i]->tag) == 0) { factory = factories[i]; break; } } if (!factory) { fprintf(stderr, "Couldn't find native window code for %s driver\n", driver); quit(2); } printf("Creating native window for %s driver\n", driver); native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H); if (!native_window) { fprintf(stderr, "Couldn't create native window\n"); quit(3); } window = SDL_CreateWindowFrom(native_window); if (!window) { fprintf(stderr, "Couldn't create SDL window: %s\n", SDL_GetError()); quit(4); } SDL_SetWindowTitle(window, "SDL Native Window Test"); /* Create the renderer */ if (SDL_CreateRenderer(window, -1, 0) < 0) { fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); quit(5); } /* Clear the window, load the sprite and go! */ SDL_SelectRenderer(window); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(); sprite = LoadSprite(window, "icon.bmp"); if (!sprite) { quit(6); } /* Allocate memory for the sprite info */ SDL_GetWindowSize(window, &window_w, &window_h); SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h); positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); if (!positions || !velocities) { fprintf(stderr, "Out of memory!\n"); quit(2); } srand(time(NULL)); for (i = 0; i < NUM_SPRITES; ++i) { positions[i].x = rand() % (window_w - sprite_w); positions[i].y = rand() % (window_h - sprite_h); positions[i].w = sprite_w; positions[i].h = sprite_h; velocities[i].x = 0; velocities[i].y = 0; while (!velocities[i].x && !velocities[i].y) { velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; } } /* Main render loop */ done = 0; while (!done) { /* Check for events */ while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_EXPOSED: SDL_SelectRenderer(event.window.windowID); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(); break; } break; case SDL_QUIT: done = 1; break; default: break; } } MoveSprites(window, sprite); } quit(0); }
int main(int argc, char *argv[]) { int i, done; SDL_Event event; Uint32 then, now, frames; Uint64 seed; /* Initialize parameters */ num_sprites = NUM_SPRITES; /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } state->window_flags |= SDL_WINDOW_RESIZABLE; for (i = 1; i < argc;) { int consumed; consumed = SDLTest_CommonArg(state, i); if (consumed == 0) { consumed = -1; if (SDL_strcasecmp(argv[i], "--blend") == 0) { if (argv[i + 1]) { if (SDL_strcasecmp(argv[i + 1], "none") == 0) { blendMode = SDL_BLENDMODE_NONE; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { blendMode = SDL_BLENDMODE_BLEND; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { blendMode = SDL_BLENDMODE_ADD; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { blendMode = SDL_BLENDMODE_MOD; consumed = 2; } } } else if (SDL_strcasecmp(argv[i], "--iterations") == 0) { if (argv[i + 1]) { iterations = SDL_atoi(argv[i + 1]); if (iterations < -1) iterations = -1; consumed = 2; } } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { cycle_color = SDL_TRUE; consumed = 1; } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { cycle_alpha = SDL_TRUE; consumed = 1; } else if (SDL_isdigit(*argv[i])) { num_sprites = SDL_atoi(argv[i]); consumed = 1; } } if (consumed < 0) { fprintf(stderr, "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N]\n", argv[0], SDLTest_CommonUsage(state)); quit(1); } i += consumed; } if (!SDLTest_CommonInit(state)) { quit(2); } /* Create the windows, initialize the renderers, and load the textures */ sprites = (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); if (!sprites) { fprintf(stderr, "Out of memory!\n"); quit(2); } for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); } if (LoadSprite("icon.bmp") < 0) { quit(2); } /* Allocate memory for the sprite info */ positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); if (!positions || !velocities) { fprintf(stderr, "Out of memory!\n"); quit(2); } /* Position sprites and set their velocities using the fuzzer */ if (iterations >= 0) { /* Deterministic seed - used for visual tests */ seed = (Uint64)iterations; } else { /* Pseudo-random seed generated from the time */ seed = (Uint64)time(NULL); } SDLTest_FuzzerInit(seed); for (i = 0; i < num_sprites; ++i) { positions[i].x = SDLTest_RandomIntegerInRange(0, state->window_w - sprite_w); positions[i].y = SDLTest_RandomIntegerInRange(0, state->window_h - sprite_h); positions[i].w = sprite_w; positions[i].h = sprite_h; velocities[i].x = 0; velocities[i].y = 0; while (!velocities[i].x && !velocities[i].y) { velocities[i].x = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED); velocities[i].y = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED); } } /* Main render loop */ frames = 0; then = SDL_GetTicks(); done = 0; while (!done) { /* Check for events */ ++frames; while (SDL_PollEvent(&event)) { SDLTest_CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { MoveSprites(state->renderers[i], sprites[i]); } } /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); printf("%2.2f frames per second\n", fps); } quit(0); return 0; }
int main(int argc, char *argv[]) { int i, done; SDL_Event event; Uint32 then, now, frames; /* Initialize parameters */ num_sprites = NUM_SPRITES; /* Initialize test framework */ state = CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } for (i = 1; i < argc;) { int consumed; consumed = CommonArg(state, i); if (consumed == 0) { consumed = -1; if (SDL_strcasecmp(argv[i], "--blend") == 0) { if (argv[i + 1]) { if (SDL_strcasecmp(argv[i + 1], "none") == 0) { blendMode = SDL_BLENDMODE_NONE; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) { blendMode = SDL_BLENDMODE_MASK; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { blendMode = SDL_BLENDMODE_BLEND; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { blendMode = SDL_BLENDMODE_ADD; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { blendMode = SDL_BLENDMODE_MOD; consumed = 2; } } } else if (SDL_strcasecmp(argv[i], "--scale") == 0) { if (argv[i + 1]) { if (SDL_strcasecmp(argv[i + 1], "none") == 0) { scaleMode = SDL_TEXTURESCALEMODE_NONE; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) { scaleMode = SDL_TEXTURESCALEMODE_FAST; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) { scaleMode = SDL_TEXTURESCALEMODE_SLOW; consumed = 2; } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) { scaleMode = SDL_TEXTURESCALEMODE_BEST; consumed = 2; } } } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { cycle_color = SDL_TRUE; consumed = 1; } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { cycle_alpha = SDL_TRUE; consumed = 1; } else if (SDL_isdigit(*argv[i])) { num_sprites = SDL_atoi(argv[i]); consumed = 1; } } if (consumed < 0) { fprintf(stderr, "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n", argv[0], CommonUsage(state)); quit(1); } i += consumed; } if (!CommonInit(state)) { quit(2); } /* Create the windows, initialize the renderers, and load the textures */ sprites = (SDL_TextureID *) SDL_malloc(state->num_windows * sizeof(*sprites)); if (!sprites) { fprintf(stderr, "Out of memory!\n"); quit(2); } for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderRect(NULL); } if (LoadSprite("icon.bmp") < 0) { quit(2); } /* Allocate memory for the sprite info */ positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); if (!positions || !velocities) { fprintf(stderr, "Out of memory!\n"); quit(2); } srand(time(NULL)); if (scaleMode != SDL_TEXTURESCALEMODE_NONE) { sprite_w += sprite_w / 2; sprite_h += sprite_h / 2; } for (i = 0; i < num_sprites; ++i) { positions[i].x = rand() % (state->window_w - sprite_w); positions[i].y = rand() % (state->window_h - sprite_h); positions[i].w = sprite_w; positions[i].h = sprite_h; velocities[i].x = 0; velocities[i].y = 0; while (!velocities[i].x && !velocities[i].y) { velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; } } /* Main render loop */ frames = 0; then = SDL_GetTicks(); done = 0; while (!done) { /* Check for events */ ++frames; while (SDL_PollEvent(&event)) { CommonEvent(state, &event, &done); switch (event.type) { case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_EXPOSED: SDL_SelectRenderer(event.window.windowID); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderRect(NULL); break; } break; default: break; } } for (i = 0; i < state->num_windows; ++i) { MoveSprites(state->windows[i], sprites[i]); } } /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); printf("%2.2f frames per second\n", fps); } quit(0); }