/* ../test/common.h */ static void dao__CommonUsage( DaoProcess *_proc, DaoValue *_p[], int _n ) { CommonState* state = (CommonState*) DaoValue_TryCastCdata( _p[0], dao_type_CommonState ); const char* _CommonUsage = CommonUsage( state ); DaoProcess_PutMBString( _proc, (char*) _CommonUsage ); }
void svConfServer::Usage(bool version) { svLog("Suva Server v%s Protocol v%d.%d: %s", PACKAGE_VERSION, _SUVA_PROTO_VER_MAJOR, _SUVA_PROTO_VER_MINOR, _SUVA_VER_RELEASE); if (!version) CommonUsage(); throw svExConfUsageRequest(); }
int main(int argc, char *argv[]) { int i, done; SDL_Event event; /* Initialize test framework */ state = CommonCreateState(argv, SDL_INIT_VIDEO); if (!state) { return 1; } state->skip_renderer = SDL_TRUE; for (i = 1; i < argc;) { int consumed; consumed = CommonArg(state, i); if (consumed == 0) { consumed = -1; } if (consumed < 0) { fprintf(stderr, "Usage: %s %s\n", argv[0], CommonUsage(state)); quit(1); } i += consumed; } if (!CommonInit(state)) { quit(2); } /* Main render loop */ done = 0; while (!done) { /* Check for events */ while (SDL_PollEvent(&event)) { CommonEvent(state, &event, &done); if (event.type == SDL_WINDOWEVENT) { if (event.window.event == SDL_WINDOWEVENT_MOVED) { SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); if (window) { printf("Window %d moved to %d,%d (display %d)\n", event.window.windowID, event.window.data1, event.window.data2, SDL_GetWindowDisplay(window)); } } } } } quit(0); // keep the compiler happy ... return(0); }
int main(int argc, char *argv[]) { int fsaa, accel; int value; int i, done; SDL_DisplayMode mode; SDL_Event event; Uint32 then, now, frames; int status; /* Initialize parameters */ fsaa = 0; accel = 0; /* 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) { if (SDL_strcasecmp(argv[i], "--fsaa") == 0) { ++fsaa; consumed = 1; } else if (SDL_strcasecmp(argv[i], "--accel") == 0) { ++accel; consumed = 1; } else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) { i++; if (!argv[i]) { consumed = -1; } else { depth = SDL_atoi(argv[i]); consumed = 1; } } else { consumed = -1; } } if (consumed < 0) { fprintf(stderr, "Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0], CommonUsage(state)); quit(1); } i += consumed; } /* Set OpenGL parameters */ state->window_flags |= SDL_WINDOW_OPENGL; state->gl_red_size = 5; state->gl_green_size = 5; state->gl_blue_size = 5; state->gl_depth_size = depth; if (fsaa) { state->gl_multisamplebuffers=1; state->gl_multisamplesamples=fsaa; } if (accel) { state->gl_accelerated=1; } if (!CommonInit(state)) { quit(2); } context = SDL_calloc(state->num_windows, sizeof(context)); if (context == NULL) { fprintf(stderr, "Out of memory!\n"); quit(2); } /* Create OpenGL ES contexts */ for (i = 0; i < state->num_windows; i++) { context[i] = SDL_GL_CreateContext(state->windows[i]); if (!context[i]) { fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); quit(2); } } if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { SDL_GL_SetSwapInterval(1); } else { SDL_GL_SetSwapInterval(0); } SDL_GetCurrentDisplayMode(&mode); printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); printf("\n"); printf("Vendor : %s\n", glGetString(GL_VENDOR)); printf("Renderer : %s\n", glGetString(GL_RENDERER)); printf("Version : %s\n", glGetString(GL_VERSION)); printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); printf("\n"); status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); if (!status) { printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); } else { fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); if (!status) { printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); } else { fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); if (!status) { printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); } else { fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); if (!status) { printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value); } else { fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); } if (fsaa) { status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); if (!status) { printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); } else { fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); } status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); if (!status) { printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } else { fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); } } if (accel) { status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); if (!status) { printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); } else { fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); } } /* Set rendering settings for each context */ for (i = 0; i < state->num_windows; ++i) { status = SDL_GL_MakeCurrent(state->windows[i], context[i]); if (status) { printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ continue; } glViewport(0, 0, state->window_w, state->window_h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); } /* Main render loop */ frames = 0; then = SDL_GetTicks(); done = 0; while (!done) { /* Check for events */ ++frames; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_RESIZED: for (i = 0; i < state->num_windows; ++i) { if (event.window.windowID == state->windows[i]) { status = SDL_GL_MakeCurrent(state->windows[i], context[i]); if (status) { printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); break; } /* Change view port to the new window dimensions */ glViewport(0, 0, event.window.data1, event.window.data2); /* Update window content */ Render(); SDL_GL_SwapWindow(state->windows[i]); break; } } break; } } CommonEvent(state, &event, &done); } for (i = 0; i < state->num_windows; ++i) { status = SDL_GL_MakeCurrent(state->windows[i], context[i]); if (status) { printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ continue; } Render(); SDL_GL_SwapWindow(state->windows[i]); } } /* Print out some timing information */ now = SDL_GetTicks(); if (now > then) { printf("%2.2f frames per second\n", ((double) frames * 1000) / (now - then)); } 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); }
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; } state->window_flags |= SDL_WINDOW_RESIZABLE; 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], "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_sprites = SDL_atoi(argv[i]); consumed = 1; } } if (consumed < 0) { fprintf(stderr, "Usage: %s %s [--blend none|blend|add|mod] [--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_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); } srand((unsigned int)time(NULL)); 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); } 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 mouse_begin_x = -1, mouse_begin_y = -1; int i, done; SDL_Event event; Uint32 then, now, frames; /* Initialize parameters */ num_objects = NUM_OBJECTS; /* 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], "--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) { fprintf(stderr, "Usage: %s %s [--blend none|mask|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", argv[0], CommonUsage(state)); return 1; } i += consumed; } if (!CommonInit(state)) { return 2; } /* Create the windows and initialize the renderers */ for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(); } srand(time(NULL)); /* 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_MOUSEBUTTONDOWN: if (event.button.which == 0) { mouse_begin_x = event.button.x; mouse_begin_y = event.button.y; } break; case SDL_MOUSEBUTTONUP: if (event.button.which == 0) { if (event.button.button == 3) add_line(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); if (event.button.button == 1) add_rect(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); } break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case 'l': if (event.key.keysym.mod & KMOD_SHIFT) num_lines = 0; else add_line(rand() % 640, rand() % 480, rand() % 640, rand() % 480); break; case 'r': if (event.key.keysym.mod & KMOD_SHIFT) num_rects = 0; else add_rect(rand() % 640, rand() % 480, rand() % 640, rand() % 480); break; } break; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_EXPOSED: SDL_SelectRenderer(SDL_GetWindowFromID(event.window.windowID)); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(); break; } break; default: break; } } for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_RenderClear(); DrawRects(state->windows[i]); DrawPoints(state->windows[i]); DrawRectRectIntersections(state->windows[i]); DrawLines(state->windows[i]); DrawRectLineIntersections(state->windows[i]); SDL_RenderPresent(); } } CommonQuit(state); /* 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); } return 0; }