static bool_t plugin_init(void) { #if ENABLE_NLS (void)setlocale(LC_MESSAGES, ""); (void)bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); (void)textdomain(GETTEXT_PACKAGE); #endif g_message(_("Infinity commands:\n" "- Space:\tchange effect.\n" "- Tab:\t\ttoggle full-screen.\n" "- Up/Down:\tup/down main volume.\n" "- Left/Right:\treward/forward actual played song, if any.\n" "- z:\t\tprevious song.\n" "- x:\t\tplay.\n" "- c:\t\tpause.\n" "- v:\t\tstop.\n" "- b:\t\tnext song.\n" "- Enter:\tswitch to interactive mode.\n\t\t(works only if infinity was configured with --enable-debug option)\n" "- F11:\t\tscreenshot.\n" "- F12:\t\tchange palette.")); config_plugin_load_prefs(); renderer_init(); return TRUE; }
int bina_init(bina_window_t* window) { /* Init SDL. */ if (sdl_init(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "sdl: unable to initialize: %s\n", sdl_get_error()); return BINA_LIB_ERROR; } /* Be verbose in logs. */ sdl_log_set_all_priority(SDL_LOG_PRIORITY_VERBOSE); #ifdef HAVE_STDIO_H /* Set up our own custom log function without userdata. */ sdl_log_set_output_function(log_custom, NULL); #endif if (window) { m.window = sdl_create_window(window->title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window->width, window->height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); if (!m.window) { sdl_log_error(SDL_LOG_CATEGORY_APPLICATION, "sdl: unable to create window: %s", sdl_get_error()); return BINA_LIB_ERROR; } } return renderer_init(m.window); }
//initalizes all game systems int game_system_init(game_system_t* sys){ //initalization if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0){ printf(M_SDL_INIT_ERROR); exit(0); } //depth and color buffer properities SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); //joystick initalization if(SDL_NumJoysticks() < 1){ printf("No joysticks found\n"); } SDL_Joystick *joy = SDL_JoystickOpen(0); if(joy != NULL){ printf("Opened Joystick 0\n"); printf("Name: %s\n", SDL_JoystickName(0)); printf("Number of Axes: %d\n", SDL_JoystickNumAxes(0)); printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(joy)); printf("Number of Balls: %d\n", SDL_JoystickNumBalls(joy)); } //init random number generator srand(time(0)); //renderer renderer_init(&sys->renderer); default_game_renderer_settings(&sys->renderer); //load default settings renderer_reload(&sys->renderer); //set inital state sys->state = STATE_INTRO; //read record sys->best_score = 0; FILE* best = fopen("data/best","r"); if(best == NULL){ best = fopen("data/best","w"); fprintf(best,"%d",0); } else{ fscanf(best,"%d",&sys->best_score); } fclose(best); return 0; }
void gb_init(void) { lcd_init(); rom_init(); apu_init();// ROMより後に作られたし mbc_init(); cpu_init(); sgb_init(); cheat_init(); apu_reset(); mbc_reset(); //target=NULL; renderer_init(); gb_reset(); hook_ext=false; use_gba=false; }
int main() { #ifdef EMULATION emu_init(); #endif irq_setmask(0); irq_enable(1); uart_async_init(); banner(); brd_init(); cpustats_init(); time_init(); mem_init(); vga_init(); snd_init(); pfpu_init(); tmu_init(); renderer_init(); apipe_init(); rpipe_init(); slowout_init(); hdlcd_init(); ui_init(); shell_init(); while(1) { if(readchar_nonblock()) shell_input(readchar()); apipe_service(); rpipe_service(); #ifdef EMULATION emu_service(); #endif } return 0; }
/* * SDL_main */ int SDL_main(int argc, char* argv[]) { SDL_Event event; SDL_Surface *screen, *icon; putenv(strdup("SDL_VIDEO_CENTERED=1")); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return EXIT_FAILURE; } icon = SDL_LoadBMP("gui/icon.bmp"); SDL_WM_SetIcon(icon, NULL); SDL_WM_SetCaption("Convex Hull Testing", "Convex Hull Testing"); SDL_ShowCursor(SDL_DISABLE); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, etrue); //Initialize window // | SDL_FULLSCREEN screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_OPENGL | SDL_NOFRAME); if(!screen) { printf("Unable to set video mode: %s\n", SDL_GetError()); return EXIT_FAILURE; } SDL_WarpMouse(512.0, 384.0); //gameState = STATE_MAINMENU; timer_init(); renderer_init(); world_init(); //model_init(); //Main loop while(!user_exit) { //Handle input while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: input_keyDown(event.key.keysym.sym); break; case SDL_KEYUP: input_keyUp(event.key.keysym.sym); break; case SDL_MOUSEMOTION: input_mouseMove(event.motion.x, event.motion.y); break; case SDL_QUIT: user_exit = etrue; } } timer_update(); while(timer.accumulated >= TIMESTEP) { input_update(); world_update(); timer.accumulated -= TIMESTEP; } world_lerpPositions(timer.accumulated); renderer_drawFrame(); } SDL_Quit(); return EXIT_SUCCESS; }
int main(int argc, char** argv) { //stbi_set_flip_vertically_on_load(1); if(SDL_Init(SDL_INIT_EVERYTHING) != 0) { Log_Error("Could not init SDL"); Log_Error(SDL_GetError()); return 1; } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); int32 window_display_index = 0; #if 1 window_display_index = 1; #endif SDL_Window* window = SDL_CreateWindow("Rituals", SDL_WINDOWPOS_CENTERED_DISPLAY(window_display_index), SDL_WINDOWPOS_CENTERED_DISPLAY(window_display_index), 1280, 720, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS); if(window == NULL) { Log_Error("Could not create window"); Log_Error(SDL_GetError()); return 1; } printf("%s \n", SDL_GetError()); SDL_GLContext glctx = SDL_GL_CreateContext(window); if(ogl_LoadFunctions() == ogl_LOAD_FAILED) { Log_Error("Could not load OpenGL 3.3 functions..."); return 1; } int ret = SDL_GL_SetSwapInterval(-1); { #define _check_gl_attribute(attr, val) int _##attr##_val; \ int _##attr##_success = SDL_GL_GetAttribute(attr, &_##attr##_val); \ gl_checks[gl_check_count++] = _##attr##_val == val; \ gl_names[gl_check_count - 1] = #attr; \ gl_vals[gl_check_count - 1] = _##attr##_val; \ gl_exp_vals[gl_check_count - 1] = val; //check if we got everything bool gl_checks[64]; char* gl_names[64]; int gl_vals[64]; int gl_exp_vals[64]; isize gl_check_count = 0; _check_gl_attribute(SDL_GL_RED_SIZE, 8); _check_gl_attribute(SDL_GL_GREEN_SIZE, 8); _check_gl_attribute(SDL_GL_BLUE_SIZE, 8); _check_gl_attribute(SDL_GL_ALPHA_SIZE, 8); _check_gl_attribute(SDL_GL_DOUBLEBUFFER, 1); _check_gl_attribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); _check_gl_attribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); _check_gl_attribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); _check_gl_attribute(SDL_GL_ACCELERATED_VISUAL, 1); _check_gl_attribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); for(isize i = 0; i < gl_check_count; ++i) { printf("%s %s: wanted %d, got %d \n", gl_names[i], gl_checks[i] ? "succeeeded" : "failed", gl_exp_vals[i], gl_vals[i]); } } // Game initializiation game = Allocate(Game, 1); { game->window = window; game->state = Game_State_None; game->meta_arena = Allocate(Memory_Arena, 1); init_memory_arena(game->meta_arena, isz(Memory_Arena) * 10); game->game_arena = new_memory_arena(Kilobytes(64), game->meta_arena); game->asset_arena = new_memory_arena(Megabytes(512), game->meta_arena); game->temp_arena = new_memory_arena(Megabytes(64), game->meta_arena); game->play_arena = new_memory_arena(Megabytes(512), game->meta_arena); game->renderer_arena = new_memory_arena(Megabytes(32), game->meta_arena); game->base_path = SDL_GetBasePath(); game->base_path_length = strlen(game->base_path); game->input = Arena_Push_Struct(game->game_arena, Game_Input); game->input->scancodes = Arena_Push_Array(game->game_arena, int8, SDL_NUM_SCANCODES); game->input->keycodes = Arena_Push_Array(game->game_arena, int8, SDL_NUM_SCANCODES); game->input->mouse = Arena_Push_Array(game->game_arena, int8, 16); init_random(&game->r, time(NULL)); //TODO(will) load window settings from file game->window_size = v2i(1280, 720); game->scale = 1.0f; game->renderer = Arena_Push_Struct(game->game_arena, Renderer); renderer_init(game->renderer, game->renderer_arena); renderer = game->renderer; input = game->input; } load_assets(); bool running = true; SDL_Event event; glClearColor(0.1f, 0.1f, 0.1f, 1.0f); //glClearColor(1, 1, 1, 1); play_state->current_time = SDL_GetTicks(); play_state->prev_time = play_state->current_time; while(running) { uint64 start_ticks = SDL_GetTicks(); if(game->input->num_keys_down < 0) game->input->num_keys_down = 0; if(game->input->num_mouse_down < 0) game->input->num_mouse_down = 0; if(game->input->num_keys_down > 0) for(int64 i = 0; i < SDL_NUM_SCANCODES; ++i) { int8* t = game->input->scancodes + i; if(*t == State_Just_Released) { *t = State_Released; } else if(*t == State_Just_Pressed) { *t = State_Pressed; } t = game->input->keycodes + i; if(*t == State_Just_Released) { *t = State_Released; } else if(*t == State_Just_Pressed) { *t = State_Pressed; } } if(game->input->num_mouse_down > 0) for(int64 i = 0; i < 16; ++i) { int8* t = game->input->mouse + i; if(*t == State_Just_Released) { *t = State_Released; } else if(*t == State_Just_Pressed) { *t = State_Pressed; } } while(SDL_PollEvent(&event)) { //TODO(will) handle text input switch(event.type) { case SDL_QUIT: running = false; break; case SDL_WINDOWEVENT: update_screen(); break; case SDL_KEYDOWN: game->input->num_keys_down++; if(!event.key.repeat) { game->input->scancodes[event.key.keysym.scancode] = State_Just_Pressed; if(event.key.keysym.sym < SDL_NUM_SCANCODES) { game->input->keycodes[event.key.keysym.sym] = State_Just_Pressed; } } break; case SDL_KEYUP: game->input->num_keys_down--; if(!event.key.repeat) { game->input->scancodes[event.key.keysym.scancode] = State_Just_Released; if(event.key.keysym.sym < SDL_NUM_SCANCODES) { game->input->keycodes[event.key.keysym.sym] = State_Just_Released; } } break; case SDL_MOUSEBUTTONDOWN: game->input->num_mouse_down++; game->input->mouse[event.button.button] = State_Just_Pressed; break; case SDL_MOUSEBUTTONUP: game->input->num_mouse_down--; game->input->mouse[event.button.button] = State_Just_Released; break; } } int mx, my; SDL_GetMouseState(&mx, &my); input->mouse_x = mx; input->mouse_y = my; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); update(); SDL_GL_SwapWindow(window); uint64 frame_ticks = SDL_GetTicks() - start_ticks; //if(frame_ticks > 18) printf("Slow frame! %d\n", frame_ticks); } SDL_Quit(); return 0; }
int main( void ) { sgui_widget *butt, *check, *check2, *label; sgui_window_description desc; sgui_window* subwnd; sgui_window* subwnd2; sgui_context* ctx; sgui_window* wnd; int selection; puts( "Select rendering backend: " ); puts( " 1) OpenGL(R) old" ); puts( " 2) OpenGL(R) 3.0+ core" ); puts( " 3) Direct3D(R) 9" ); puts( " 4) Direct3D(R) 11" ); puts( "\n 0) quit\n" ); selection = 0; scanf( "%d", &selection ); switch( selection ) { case 1: selection = SGUI_OPENGL_COMPAT; break; case 2: selection = SGUI_OPENGL_CORE; break; case 3: selection = SGUI_DIRECT3D_9; break; case 4: selection = SGUI_DIRECT3D_11; break; default: return 0; } sgui_init( ); /* create a window */ memset( &desc, 0, sizeof(desc) ); desc.width = WIDTH; desc.height = HEIGHT; desc.flags = SGUI_FIXED_SIZE|SGUI_DOUBLEBUFFERED; desc.backend = selection; desc.bits_per_pixel = 32; desc.depth_bits = 16; wnd = sgui_window_create_desc( &desc ); sgui_window_set_title( wnd, "subwm" ); sgui_window_move_center( wnd ); sgui_window_set_visible( wnd, SGUI_VISIBLE ); sgui_window_make_current( wnd ); sgui_window_set_vsync( wnd, 1 ); ctx = sgui_window_get_context( wnd ); renderer_init( selection, ctx ); /* */ wm = sgui_ctx_wm_create( wnd ); sgui_window_set_userptr( wnd, wm ); sgui_window_on_event( wnd, (sgui_window_callback)sgui_ctx_wm_inject_event ); /* create some sub windows */ subwnd = sgui_ctx_wm_create_window( wm, 256, 128, 0 ); subwnd2 = sgui_ctx_wm_create_window( wm, 256, 128, 0 ); sgui_window_set_visible( subwnd, 1 ); sgui_window_set_visible( subwnd2, 1 ); sgui_window_move( subwnd2, 10, 10 ); sgui_window_set_title( subwnd, "Sub Window" ); sgui_window_set_title( subwnd2, "Another Window" ); /* create a few widgets */ butt = sgui_button_create( 10, 35, 60, 25, "Button", 0 ); check = sgui_checkbox_create( 10, 65, "OpenGL" ); check2 = sgui_checkbox_create( 10, 90, "Texture" ); label = sgui_label_create( 10, 35, "Hello, world!\n\n" "From a <b><i>sub</i></b> window." ); sgui_button_set_state( check, 1 ); sgui_button_set_state( check2, 1 ); /* add the widgets to the sub windows */ sgui_window_add_widget( subwnd, butt ); sgui_window_add_widget( subwnd, check ); sgui_window_add_widget( subwnd, check2 ); sgui_window_add_widget( subwnd2, label ); /* main loop */ while( sgui_main_loop_step( ) ) { renderer_draw( selection, ctx ); if( drawgui ) sgui_ctx_wm_draw_gui( wm ); sgui_window_swap_buffers( wnd ); } /* clean up */ sgui_window_destroy( subwnd ); sgui_window_destroy( subwnd2 ); sgui_widget_destroy( butt ); sgui_widget_destroy( check ); sgui_widget_destroy( check2 ); sgui_widget_destroy( label ); sgui_ctx_wm_destroy( wm ); sgui_window_release_current( wnd ); sgui_window_destroy( wnd ); sgui_deinit( ); return 0; }
int main ( int argc, char **argv ) { g_type_init(); Display *display; // catch help request if ( find_arg( argc, argv, "-help" ) >= 0 || find_arg( argc, argv, "--help" ) >= 0 || find_arg( argc, argv, "-h" ) >= 0 ) { help(); return EXIT_SUCCESS; } // Get DISPLAY const char *display_str= getenv( "DISPLAY" ); if ( !( display = XOpenDisplay( display_str ) ) ) { fprintf( stderr, "cannot open display!\n" ); return EXIT_FAILURE; } // Setup error handler. XSync( display, False ); xerror = XSetErrorHandler( X11_oops ); XSync( display, False ); // Initialize renderer renderer_init( display ); // Get monitor layout. (xinerama aware) MMB_Screen *mmb_screen = mmb_screen_create( display ); // Check input file. char *image_file = NULL; find_arg_str( argc, argv, "-input", &image_file ); if ( image_file ) { int clip = ( find_arg( argc, argv, "-clip" ) >= 0 ); GdkPixbuf *pb = renderer_create_empty_background( mmb_screen ); if ( renderer_overlay_wallpaper( pb, image_file, mmb_screen,clip ) ) { char *output_file = NULL; find_arg_str( argc, argv, "-output", &output_file ); if ( output_file ) { renderer_store_image( pb, output_file ); } else { renderer_update_X11_background( display, pb ); } } g_object_unref( pb ); } // Print layout if ( find_arg( argc, argv, "-print" ) >= 0 ) { mmb_screen_print( mmb_screen ); } // Cleanup mmb_screen_free( &mmb_screen ); XCloseDisplay( display ); }
int main(int argc, char *argv[]) { char *host = NULL; char *renderer = NULL; int width = 800; int height = 600; int fullscreen = 0; #ifdef EVENT_HOST host = EVENT_HOST; #endif #ifdef DEFAULT_RENDERER renderer = TOSTRING(DEFAULT_RENDERER); #endif // GUI Environment setzt default Renderer um. if (getenv("GUI")) renderer = getenv("GUI"); #ifdef WIN32 char *sep = strrchr(argv[0], '\\'); if (sep) { *sep = '\0'; chdir(argv[0]); } // Spezialfaelle fuer Windows Screensaver Aufrufe if (argc == 2 && stricmp(argv[1], "/s") == 0) { host = "infon.dividuum.de"; width = 1024, height = 768, fullscreen = 1; goto screen_saver_start; } else if (argc == 3 && stricmp(argv[1], "/p") == 0) { exit(EXIT_SUCCESS); } else if (argc == 2 && strstr(argv[1], "/c:") == argv[1]) { die("There are no settings"); } #endif // Keine Fehler auf stderr opterr = 0; int opt; while ((opt = getopt(argc, argv, ":fvx:y:r:h")) != -1) { switch (opt) { case '?': die("you specified an unknown option -%c.", optopt); case ':': die("missing argument to option -%c.", optopt); case 'r': renderer = optarg; break; case 'f': fullscreen = 1; break; case 'x': width = atoi(optarg); break; case 'y': height = atoi(optarg); break; case 'h': die("usage: %s [-r <renderer>] [-f] [-x <width>] [-y <height>] [-v] [-h] <server[:port]>\n" "\n" " -r <renderer> - renderer to use (sdl_gui, gl_gui, ...)\n" " -x <width> - initial screen width.\n" " -y <height> - initial screen height.\n" " -f - start in fullscreen mode.\n" " -v - display version information.\n" " -h - this help.\n" "\n" "<server[:port]> - ip/hostname of an infon game server.\n" " if no port is given, 1234 is used.\n", argv[0]); case 'v': info(); exit(EXIT_SUCCESS); } } switch (argc - optind) { case 0: break; case 1: host = argv[optind]; break; default: die("you specified more than one game server hostname"); } if (!renderer) die("no renderer specified. use the '-r <renderer>' option"); #ifdef WIN32 if (!host) { if (yesno("You did not specify a game server.\nConnect to 'infon.dividuum.de:1234'?")) host = "infon.dividuum.de"; else die("You must supply the game servers hostname\n" "as a command line parameter.\n\n" "Example: 'infon.exe infon.dividuum.de'\n\n" "Visit http://infon.dividuum.de/ for help."); } #else if (!host) die("usage: %s [options] <server[:port]>\n" "see %s -h for a full list of options", argv[0], argv[0]); #endif #ifndef WIN32 signal(SIGTERM, sighandler); signal(SIGINT, sighandler); signal(SIGPIPE, SIG_IGN); #else screen_saver_start: #endif srand(time(NULL)); gettimeofday(&start, NULL); if (!renderer_init(renderer)) die("cannot initialize the renderer '%s'", renderer); if (!renderer_open(width, height, fullscreen)) die("cannot start the renderer '%s'. sorry", renderer); client_init(host); client_game_init(); int lastticks = get_tick(); while (!signal_received && !renderer_wants_shutdown() && client_is_connected()) { int nowticks = get_tick(); int delta = nowticks - lastticks; if (nowticks < lastticks || nowticks > lastticks + 1000) { // Timewarp? lastticks = nowticks; continue; } lastticks = nowticks; // IO Lesen/Schreiben client_tick(delta); client_creature_move(delta); renderer_tick(game_time, delta); game_time += delta; } client_game_shutdown(); client_shutdown(); renderer_close(); renderer_shutdown(); return EXIT_SUCCESS; }