void winsys_process_events() { SDL_Event event; while(true){ SDL_LockAudio(); SDL_UnlockAudio(); while(SDL_PollEvent(&event)){ switch(event.type){ case SDL_KEYDOWN: loop_keyboard_func(event.key.keysym.sym, event.key.keysym.mod, false); break; case SDL_KEYUP: loop_keyboard_func( event.key.keysym.sym, event.key.keysym.mod, true); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: loop_mouse_func( event.button.button, event.button.state, ppogl::Vec2i(event.button.x, event.button.y)); break; case SDL_MOUSEMOTION: if(event.motion.state){ // buttons are down loop_mouse_motion_func(ppogl::Vec2i(event.motion.x, event.motion.y)); }else{ // no buttons are down loop_mouse_motion_func(ppogl::Vec2i(event.motion.x, event.motion.y)); } break; case SDL_VIDEORESIZE: PPConfig.setInt("x_resolution",event.resize.w); PPConfig.setInt("y_resolution",event.resize.h); setup_video_mode(); reshape(ppogl::Vec2i(event.resize.w, event.resize.h)); break; case SDL_QUIT: winsys_exit(0); break; } SDL_LockAudio(); SDL_UnlockAudio(); } GameMode::mainLoop(); // delay for 1ms to alow other threads to do some work SDL_Delay(1); } PP_NOT_REACHED(); }
void winsys_init(const char *window_title, const char *icon_title) { PP_MESSAGE("Init SDL"); Uint32 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; if(SDL_Init(sdl_flags) < 0){ PP_ERROR("Couldn't initialize SDL: " << SDL_GetError()); } // init video setup_video_mode(); SDL_WM_SetCaption(window_title, icon_title); SDL_EnableKeyRepeat( 0, 0 ); }
void wii_video_init(void) { VIDEO_Init(); GXRModeObj *mode = VIDEO_GetPreferredMode(NULL); setup_video_mode(mode); GX_Init(gx_fifo, sizeof(gx_fifo)); GX_SetDispCopyGamma(GX_GM_1_0); GX_SetCullMode(GX_CULL_NONE); GX_SetClipMode(GX_CLIP_DISABLE); init_vtx(mode); build_disp_list(); g_filter = true; g_vsync = true; }
void init_stuff() { int seed; Uint32 (*my_timer_pointer) (unsigned int) = my_timer; //TODO: process command line options chdir(datadir); //Initialize all strings init_translatables(); #ifdef WRITE_XML load_translatables();//Write to the current working directory - hopefully we'll have write rights here... #endif //read the config file read_config(); //Parse command line options read_command_line(); //OK, we have the video mode settings... setup_video_mode(full_screen,video_mode); //now you may set the video mode using the %<foo> in-game video_mode_set=1; //Good, we should be in the right working directory - load all translatables from their files load_translatables(); init_video(); resize_window(); init_gl_extensions(); #ifdef CAL3D create_cal3d_model(); init_cal3d_model(); #endif seed = time (NULL); srand (seed); cache_system_init(MAX_CACHE_SYSTEM); init_texture_cache(); init_md2_cache(); init_e3d_cache(); init_2d_obj_cache(); load_ignores(); load_filters(); load_e3d_list(); load_e2d_list(); load_part_list(); load_knowledge_list(); load_cursors(); build_cursors(); change_cursor(CURSOR_ARROW); build_glow_color_table(); init_actors_lists(); memset(tile_list, 0, sizeof(tile_list)); memset(lights_list, 0, sizeof(lights_list)); init_particles_list(); memset(actors_defs, 0, sizeof(actors_defs)); init_actor_defs(); load_map_tiles(); //lights setup build_global_light_table(); build_sun_pos_table(); reset_material(); init_lights(); disable_local_lights(); init_colors(); clear_error_log(); clear_conn_log(); clear_thunders(); build_rain_table(); read_bin_cfg(); build_levels_table();//for some HUD stuff init_scale_array(); if(!no_sound)init_sound(); //initialize the fonts init_fonts(); check_gl_errors(); //load the necesary textures //font_text=load_texture_cache("./textures/font.bmp",0); icons_text=load_texture_cache("./textures/gamebuttons.bmp",0); hud_text=load_texture_cache("./textures/gamebuttons2.bmp",0); cons_text=load_texture_cache("./textures/console.bmp",255); sky_text_1=load_texture_cache("./textures/sky.bmp",70); particle_textures[0]=load_texture_cache("./textures/particle0.bmp",0); particle_textures[1]=load_texture_cache("./textures/particle1.bmp",0); particle_textures[2]=load_texture_cache("./textures/particle2.bmp",0); particle_textures[3]=load_texture_cache("./textures/particle3.bmp",0); particle_textures[4]=load_texture_cache("./textures/particle4.bmp",0); particle_textures[5]=load_texture_cache("./textures/particle5.bmp",0); particle_textures[6]=load_texture_cache("./textures/particle6.bmp",0); particle_textures[7]=load_texture_cache("./textures/particle7.bmp",0); items_text_1=load_texture_cache("./textures/items1.bmp",0); items_text_2=load_texture_cache("./textures/items2.bmp",0); items_text_3=load_texture_cache("./textures/items3.bmp",0); items_text_4=load_texture_cache("./textures/items4.bmp",0); items_text_5=load_texture_cache("./textures/items5.bmp",0); items_text_6=load_texture_cache("./textures/items6.bmp",0); items_text_7=load_texture_cache("./textures/items7.bmp",0); items_text_8=load_texture_cache("./textures/items8.bmp",0); items_text_9=load_texture_cache("./textures/items9.bmp",0); portraits1_tex=load_texture_cache("./textures/portraits1.bmp",0); portraits2_tex=load_texture_cache("./textures/portraits2.bmp",0); portraits3_tex=load_texture_cache("./textures/portraits3.bmp",0); portraits4_tex=load_texture_cache("./textures/portraits4.bmp",0); portraits5_tex=load_texture_cache("./textures/portraits5.bmp",0); halo_tex=load_texture_cache("./textures/halo.bmp",0); if(have_multitexture)ground_detail_text=load_texture_cache("./textures/ground_detail.bmp",255); check_gl_errors(); create_char_error_str[0]=0; init_opening_interface(); init_hud_interface(); if(SDLNet_Init()<0) { char str[120]; sprintf(str,"%s: %s\n",failed_sdl_net_init,SDLNet_GetError()); log_error(str); SDLNet_Quit(); SDL_Quit(); exit(2); } if(SDL_InitSubSystem(SDL_INIT_TIMER)<0) { char str[120]; sprintf(str, "%s: %s\n", failed_sdl_timer_init,SDL_GetError()); log_error(str); SDL_Quit(); exit(1); } SDL_SetTimer (1000/(18*4), my_timer_pointer); ReadXML("languages/en/Encyclopedia/index.xml"); read_key_config(); load_questlog(); init_buddy(); //initiate function pointers init_attribf(); //we might want to do this later. connect_to_server(); }
void init_video() { char str[400]; int rgb_size[3]; setup_video_mode(full_screen, video_mode); /* Detect the display depth */ if(!bpp) { if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) { bpp = 8; } else if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 16 ) { bpp = 16; /* More doesn't seem to work */ } else bpp=32; } //adjust the video mode accordingly if (video_mode == 0) { //do nothing } else if(bpp==16) { if(!(video_mode%2)) video_mode-=1; } else { if(video_mode%2) video_mode+=1; } /* Initialize the display */ switch (bpp) { case 8: rgb_size[0] = 2; rgb_size[1] = 3; rgb_size[2] = 3; break; case 15: case 16: rgb_size[0] = 5; rgb_size[1] = 5; rgb_size[2] = 5; break; default: rgb_size[0] = 8; rgb_size[1] = 8; rgb_size[2] = 8; break; } // Mac OS X will always use 8-8-8-8 ARGB for 32-bit screens and 5-5-5 RGB for 16-bit screens #ifndef OSX SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] ); #endif #ifdef OSX // enable V-SYNC SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 ); #endif SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 0 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 ); SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); #ifdef FSAA if (fsaa > 1) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); glDisable(GL_MULTISAMPLE); } #endif /* FSAA */ check_gl_mode(); #ifdef OTHER_LIFE SDL_WM_SetIcon(SDL_LoadBMP("ol_icon.bmp"), NULL); #else SDL_WM_SetIcon(SDL_LoadBMP("icon.bmp"), NULL); #endif /* Set the window manager title bar */ #ifdef FSAA if (fsaa > 1) { if (!SDL_SetVideoMode(window_width, window_height, bpp, flags)) { safe_snprintf(str, sizeof(str), "Can't use fsaa mode x%d, disabling it.", fsaa); LOG_TO_CONSOLE(c_yellow1, str); LOG_WARNING("%s\n", str); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); fsaa = 0; } } #endif /* FSAA */ //try to find a stencil buffer (it doesn't always work on Linux) if(!SDL_SetVideoMode(window_width, window_height, bpp, flags)) { LOG_TO_CONSOLE(c_red1,no_hardware_stencil_str); LOG_ERROR("%s\n",no_hardware_stencil_str); if(bpp!=32) { LOG_TO_CONSOLE(c_grey1,suggest_24_or_32_bit); LOG_ERROR("%s\n",suggest_24_or_32_bit); } SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0); if(!SDL_SetVideoMode( window_width, window_height, bpp, flags)) { LOG_ERROR("%s: %s\n", fail_opengl_mode, SDL_GetError()); SDL_Quit(); exit(1); } have_stencil=0; } #ifdef WINDOWS //try to see if we get hardware acceleration, or the windows generic shit { int len; GLubyte *my_string; int have_hardware; my_string=(GLubyte *)glGetString(GL_RENDERER); if (my_string == NULL) { len = 0; have_hardware = 0; LOG_TO_CONSOLE(c_red1,"glGetString(GL_RENDERER) failed"); LOG_ERROR("%s\n","glGetString(GL_RENDERER) failed"); } else { len=strlen(my_string); have_hardware=get_string_occurance("gdi generic",my_string,len,0); } if(have_hardware != -1) { //let the user know there is a problem LOG_TO_CONSOLE(c_red1,stencil_falls_back_on_software_accel); LOG_ERROR("%s\n",stencil_falls_back_on_software_accel); //first, shut down this mode we have now. SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] ); SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 0); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1); if(full_screen)flags=SDL_OPENGL|SDL_FULLSCREEN; SDL_SetVideoMode(window_width, window_height, bpp, flags); have_stencil=0; my_string=(GLubyte *)glGetString(GL_RENDERER); if (my_string == NULL) { len = 0; have_hardware = 0; LOG_TO_CONSOLE(c_red1,"glGetString(GL_RENDERER) failed"); LOG_ERROR("%s\n","glGetString(GL_RENDERER) failed"); } else { len=strlen(my_string); have_hardware=get_string_occurance("gdi generic",my_string,len,0); } if(have_hardware != -1) { //wtf, this really shouldn't happen.... //let's try a default mode, maybe Quake 2's mode, and pray it works LOG_TO_CONSOLE(c_red1,last_chance_str); LOG_ERROR("%s\n",last_chance_str); 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, 0); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1); flags=SDL_OPENGL|SDL_FULLSCREEN; full_screen=1; video_mode=2; window_width=640; window_height=480; bpp=32; SDL_SetVideoMode(window_width, window_height, bpp, flags); //see if it worked... my_string=(GLubyte *)glGetString(GL_RENDERER); if (my_string == NULL) { len = 0; have_hardware = 0; LOG_TO_CONSOLE(c_red1,"glGetString(GL_RENDERER) failed"); LOG_ERROR("%s\n","glGetString(GL_RENDERER) failed"); } else { len=strlen(my_string); have_hardware=get_string_occurance("gdi generic",my_string,len,0); } if(have_hardware != -1) { //wtf, this really shouldn't happen.... //let's try a default mode, maybe Quake 2's mode, and pray it works LOG_TO_CONSOLE(c_red1,software_mode_str); LOG_ERROR("%s\n",software_mode_str); } } } } #endif glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); //glDepthFunc(GL_LEQUAL); glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_NORMALIZE); glClearStencil(0); #ifdef ANTI_ALIAS if (anti_alias) { glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); } else { glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST); glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); glDisable(GL_POINT_SMOOTH); glDisable(GL_LINE_SMOOTH); glDisable(GL_POLYGON_SMOOTH); } #endif SDL_EnableKeyRepeat(200, 100); SDL_EnableUNICODE(1); build_video_mode_array(); SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &have_stencil); last_texture=-1; //no active texture #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE change_minimap(); check_options(); }