/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void quit(int rc) { SDL_free(sprites); SDL_free(positions); SDL_free(velocities); SDLTest_CommonQuit(state); exit(rc); }
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void quit(int rc) { if (context) { SDL_GL_DeleteContext(context); } SDLTest_CommonQuit(state); exit(rc); }
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void quit(int rc) { if (context) { /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ SDL_GL_DeleteContext(context); } SDLTest_CommonQuit(state); exit(rc); }
int main(int argc, char *argv[]) { /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } for (i = 1; i < argc; ++i) { SDLTest_CommonArg(state, i); } if (!SDLTest_CommonInit(state)) { return 2; } /* Create the windows and initialize the renderers */ for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); } srand((unsigned int)time(NULL)); if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) { return 3; }; rect.x = DEFAULT_WINDOW_WIDTH / 2; rect.y = DEFAULT_WINDOW_HEIGHT / 2; rect.w = 10; rect.h = 10; /* Main render loop */ done = 0; #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, 1); #else while (!done) { loop(); } #endif SDLTest_CommonQuit(state); return 0; }
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void quit(int rc) { int i; if (context != NULL) { for (i = 0; i < state->num_windows; i++) { if (context[i]) { SDL_GL_DeleteContext(context[i]); } } SDL_free(context); } SDLTest_CommonQuit(state); exit(rc); }
int main(int argc, char *argv[]) { int i; Uint32 then, now, frames; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Initialize parameters */ num_objects = NUM_OBJECTS; /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } 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], "--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_objects = SDL_atoi(argv[i]); consumed = 1; } } if (consumed < 0) { SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", argv[0], SDLTest_CommonUsage(state)); return 1; } i += consumed; } if (!SDLTest_CommonInit(state)) { return 2; } /* Create the windows and initialize the renderers */ for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_SetRenderDrawBlendMode(renderer, blendMode); SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); } srand((unsigned int)time(NULL)); /* Main render loop */ frames = 0; then = SDL_GetTicks(); done = 0; #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, 1); #else while (!done) { ++frames; loop(); } #endif SDLTest_CommonQuit(state); /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); SDL_Log("%2.2f frames per second\n", fps); } return 0; }
int main(int argc, char *argv[]) { int i, done; SDL_Event event; /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } for (i = 1; i < argc;i++) { SDLTest_CommonArg(state, i); } if (!SDLTest_CommonInit(state)) { return 2; } /* Create the windows and initialize the renderers */ for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); } srand((unsigned int)time(NULL)); if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) { return 3; }; rect.x = DEFAULT_WINDOW_WIDTH / 2; rect.y = DEFAULT_WINDOW_HEIGHT / 2; rect.w = 10; rect.h = 10; /* Main render loop */ done = 0; while (!done) { /* Check for events */ while (SDL_PollEvent(&event)) { SDLTest_CommonEvent(state, &event, &done); switch(event.type) { case SDL_MOUSEMOTION: { /*printf("mouse motion ABS x %d y %d REL x %d y %d\n",event.motion.x,event.motion.y,event.motion.xrel,event.motion.yrel);*/ rect.x += event.motion.xrel; rect.y += event.motion.yrel; } break; } } for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); DrawRects(renderer); SDL_RenderPresent(renderer); } } SDLTest_CommonQuit(state); return 0; }
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void quit(int rc) { SDLTest_CommonQuit(state); exit(rc); }
int main(int argc, char *argv[]) { int i; SDL_Event event; Uint32 then, now, frames; FPSmanager fpsm; /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } SDL_Log("SDL2_gfx %i.%i.%i: testframerate", SDL2_GFXPRIMITIVES_MAJOR, SDL2_GFXPRIMITIVES_MINOR, SDL2_GFXPRIMITIVES_MICRO); SDL_Log("Platform: %s", SDL_GetPlatform()); for (i = 1; i < argc;) { int consumed; consumed = SDLTest_CommonArg(state, i); if (consumed == 0) { consumed = -1; if (SDL_strcasecmp(argv[i], "--x") == 0) { if (argv[i + 1]) { x = SDL_atoi(argv[i + 1]); if (x < 0) x = 0; if (x >= WIDTH) x = WIDTH - 1; consumed = 2; } } else if (SDL_strcasecmp(argv[i], "--y") == 0) { if (argv[i + 1]) { y = SDL_atoi(argv[i + 1]); if (y < 0) y = 0; if (y >= HEIGHT) y = HEIGHT - 1; consumed = 2; } } } if (consumed < 0) { SDL_Log("Usage: %s %s [--x #] [--y #]\n", argv[0], SDLTest_CommonUsage(state)); return 1; } i += consumed; } if (!SDLTest_CommonInit(state)) { return 2; } /* Create the windows and initialize the renderers */ for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i]; SDL_RendererInfo info; SDL_GetRendererInfo(state->renderers[i], &info); SDL_Log("Renderer %i: %s %s", i, info.name, (info.flags | SDL_RENDERER_ACCELERATED) ? "(Accelerated)" : ""); SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(renderer); } /* Initialize random number generator */ srand((unsigned int)time(NULL)); /* Create common message buffer */ messageText = (char *)SDL_malloc(1024); if (messageText == NULL) { return -1; } /* Initialize framerate manager */ SDL_initFramerate(&fpsm); /* Main render loop */ frames = 0; then = SDL_GetTicks(); done = 0; while (!done) { /* Check for events */ ++frames; while (SDL_PollEvent(&event) && !done) { SDLTest_CommonEvent(state, &event, &done); } /* Do all the drawing work */ Draw(state->renderers[0], &fpsm); } /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { double fps = ((double) frames * 1000) / (now - then); SDL_Log("%2.2f frames per second\n", fps); } /* Free common message buffer */ if (messageText) { free(messageText); } /* Shutdown SDL */ SDLTest_CommonQuit(state); return 0; }