int main(int argc, char **argv) { int result = EXIT_FAILURE; if(SDL_Init(SDL_INIT_VIDEO) < 0) goto out; setupformat(); if(resize(1024, 768, false, Diagonal)) goto out_sdl; SDL_WM_SetCaption("Radmire", NULL); SDL_EnableKeyRepeat(0, 0); glinit(); setupclock(); result = run(); out_sdl: SDL_Quit(); out: return result; }
// Create a new SDL window SDLViewer::SDLViewer() : OpenGLViewer(), screen(NULL) { const SDL_VideoInfo *pSDLVideoInfo; putenv(strdup("SDL_VIDEO_WINDOW_POS=center")); // Initialise SDL Video subsystem if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) abort_program("Unable to initialize SDL: %s", SDL_GetError()); pSDLVideoInfo = SDL_GetVideoInfo(); if( !pSDLVideoInfo ) { SDL_Quit(); abort_program("SDL_GetVideoInfo() failed. SDL Error: %s", SDL_GetError()); } timer_id = 0; // NOTE: still want Ctrl-C to work, undo the SDL redirections #ifndef _WIN32 signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); #endif // Keyboard setup SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); //#ifndef PDF_CAPTURE SDL_EnableUNICODE(1); //Enable unicode character translation //Above prevents adobe 3d capture from detecting print screen key? //#endif // Save fullscreen width/height savewidth = pSDLVideoInfo->current_w; saveheight = pSDLVideoInfo->current_h; resized = false; screen = NULL; debug_print("SDL viewer created\n"); }
//constructor SDLview::SDLview() { // Init SDL video subsystem if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL video: %s\n", SDL_GetError()); exit(1); } // Init SDL audio subsystem if ( SDL_Init (SDL_INIT_AUDIO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL audio: %s\n", SDL_GetError()); exit(1); } // Set GL context attributes OpenGL_Init(); // Create GL context createSurface(); // Get GL context attributes //printAttributes (); Timing = GL_TRUE; count = 0; StrMode = GL_VENDOR; //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableKeyRepeat(1,1); SDL_WM_GrabInput(SDL_GRAB_ON); SDL_WM_SetCaption("The Sentinel", "The Sentinel"); SDL_WarpMouse(int(w_win / 2.0), int(h_win / 2.0)); }
void SDLManagerPrivate::setKeyboardRepeatRate() { int delay = SDL_DEFAULT_REPEAT_DELAY; int interval = SDL_DEFAULT_REPEAT_INTERVAL; ZString delayStr = dotFile.getValue("keyboard.repeat_delay", 1); if ( delayStr.upper() != "DEFAULT" ) { int val = dotFile.getInt("keyboard.repeat_delay", 1, delay); if ( val > 0 ) delay = val; } ZString intervalStr = dotFile.getValue("keyboard.repeat_interval", 1); if ( intervalStr.upper() != "DEFAULT" ) { int val = dotFile.getInt("keyboard.repeat_interval", 1, interval); if ( val > 0 ) interval = val; } zdebug() << "SetKeyboardRepeatRate delay" << delay << "interval" << interval; SDL_EnableKeyRepeat( delay, interval ); }
void Chat::ShowInput() { if (!check_input) { check_input = true; /* Enable key repeat when chatting :) */ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); } if (!input) { input = new Text("", c_white); msg = new Text(_("Say: "), c_red); } /* FIXME where do those constants come from ?*/ int ypos = GetMainWindow().GetHeight() - 100; msg->DrawLeftTop(Point2i(25, ypos)); if (input->GetText() != "") { input->DrawLeftTop(Point2i(25 + msg->GetWidth() + 5, ypos)); input->DrawCursor(Point2i(25 + msg->GetWidth() + 5, ypos), cursor_pos); } }
/** * Initialises the OpenGL and SDL application. This function creates the global * Gui object that can be populated by various examples. */ void init() { // We simply initialise OpenGL and SDL as we would do with any OpenGL // and SDL application. SDL_Init(SDL_INIT_VIDEO); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_OPENGL | SDL_HWACCEL); glViewport(0, 0, 640, 480); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // We want unicode for the SDLInput object to function properly. SDL_EnableUNICODE(1); // We also want to enable key repeat. SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // Now it's time to initialise the Guichan OpenGL back end // and the Guichan SDL back end. imageLoader = new gcn::OpenGLSDLImageLoader(); // The ImageLoader Guichan should use needs to be passed to the Image object // using a static function. gcn::Image::setImageLoader(imageLoader); graphics = new gcn::OpenGLGraphics(); // We need to tell the OpenGL Graphics object how big the screen is. graphics->setTargetPlane(640, 480); input = new gcn::SDLInput(); // Now we create the Gui object to be used with this OpenGL // and SDL application. globals::gui = new gcn::Gui(); // The Gui object needs a Graphics to be able to draw itself and an Input // object to be able to check for user input. In this case we provide the // Gui object with OpenGL and SDL implementations of these objects hence // making Guichan able to utilise OpenGL and SDL. globals::gui->setGraphics(graphics); globals::gui->setInput(input); }
/** * Initialize the SDL-FrameWork. Initialize SDL-Video and set some properties. * @return either NR_OK or: * - NR_FW_CANNOT_INITIALIZE * - NR_FW_ALREADY_INIT if already initialized **/ nrResult nrCFrameworkSDL::init() { if (isInitialized()) { nrLog.Log(NR_LOG_ENGINE, "nrCFrameworkSDL: WARNING: Framework already initialized"); return NR_FW_ALREADY_INIT; } // Log it nrLog.Log(NR_LOG_ENGINE, "nrCFrameworkSDL: Initialize SDL framework"); // initialize SDL-Video Interface if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { nrLog.Log(NR_LOG_ENGINE, "nrCFrameworkSDL: Failed initializing SDL Video : %s" ,SDL_GetError()); return NR_FW_CANNOT_INITIALIZE; } // activate SDL-events SDL_EventState (SDL_KEYDOWN, SDL_ENABLE); SDL_EventState (SDL_KEYUP, SDL_ENABLE); SDL_EventState (SDL_QUIT, SDL_ENABLE); SDL_EventState (SDL_MOUSEMOTION, SDL_ENABLE); SDL_EnableKeyRepeat (1,0); SDL_GetKeyState(&_keyCount); // create and full the keyboard state arrays _keyState.reset(new byte[_keyCount]); _oldKeyState.reset(new byte[_keyCount]); byte* ks = SDL_GetKeyState(NULL); memcpy(_oldKeyState.get(), ks, sizeof(byte) * _keyCount); memcpy(_keyState.get(), ks, sizeof(byte) * _keyCount); _isInitialized = true; return NR_OK; }
//Registers, creates, and shows the Window!! bool WinCreate() { //const SDL_VideoInfo* video_info; int init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; if(SDL_Init(init_flags) < 0) { return false; } if(TTF_Init()<0) { return false; } SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(500, 60); atexit(SDL_Quit); std::string version = string_format("Cataclysm: Dark Days Ahead - %s", getVersionString()); SDL_WM_SetCaption(version.c_str(), NULL); char center_string[] = "SDL_VIDEO_CENTERED=center"; // indirection needed to avoid a warning SDL_putenv(center_string); screen = SDL_SetVideoMode(WindowWidth, WindowHeight, 32, (SDL_SWSURFACE|SDL_DOUBLEBUF)); //SDL_SetColors(screen,windowsPalette,0,256); if(screen==NULL) return false; ClearScreen(); if(OPTIONS["HIDE_CURSOR"] > 0 && SDL_ShowCursor(-1)) SDL_ShowCursor(SDL_DISABLE); else SDL_ShowCursor(SDL_ENABLE); return true; };
void Frame::run() { for (int i = 0; i < sprites.size(); i++) sprites[i]->draw(); SDL_Flip(sys.screen); SDL_EnableKeyRepeat(1, SDL_DEFAULT_REPEAT_INTERVAL); // Händelseloop bool running = true; while(running) { SDL_Event ev; while (SDL_PollEvent(&ev)) { switch (ev.type) { case SDL_QUIT: running = false; break; case SDL_KEYDOWN: for(int i=0; i<sprites.size();i++) sprites[i]->keyDown(ev.key.keysym.sym); break; } // switch } // while SDL_PollEvent Uint32 white = SDL_MapRGB(sys.screen->format, 255, 255, 255); SDL_FillRect(sys.screen, NULL, white); // Fyll hela skärmen vit for(int i=0; i<sprites.size(); i++) sprites[i]->draw(); SDL_Flip(sys.screen); } // while running }
/* * Initializes the backend */ void IN_BackendInit ( in_state_t *in_state_p ) { in_state = in_state_p; m_filter = ri.Cvar_Get( "m_filter", "0", CVAR_ARCHIVE ); in_mouse = ri.Cvar_Get( "in_mouse", "0", CVAR_ARCHIVE ); freelook = ri.Cvar_Get( "freelook", "1", 0 ); lookstrafe = ri.Cvar_Get( "lookstrafe", "0", 0 ); sensitivity = ri.Cvar_Get( "sensitivity", "3", 0 ); exponential_speedup = ri.Cvar_Get( "exponential_speedup", "0", CVAR_ARCHIVE ); m_pitch = ri.Cvar_Get( "m_pitch", "0.022", 0 ); m_yaw = ri.Cvar_Get( "m_yaw", "0.022", 0 ); m_forward = ri.Cvar_Get( "m_forward", "1", 0 ); m_side = ri.Cvar_Get( "m_side", "0.8", 0 ); ri.Cmd_AddCommand( "+mlook", IN_MLookDown ); ri.Cmd_AddCommand( "-mlook", IN_MLookUp ); ri.Cmd_AddCommand( "force_centerview", IN_ForceCenterView ); mouse_x = mouse_y = 0.0; #if defined(PI) SDL_Surface *surface = SDL_SetVideoMode(0,0, 32, SDL_SWSURFACE); #endif /* SDL stuff */ SDL_EnableUNICODE( 0 ); SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); windowed_mouse = ri.Cvar_Get ("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE); in_grab = ri.Cvar_Get ("in_grab", "2", CVAR_ARCHIVE); #if defined(WIZ) || defined(CAANOO) GPH_Open(); #endif Com_Printf( "Input initialized.\n" ); }
int main(int argc, char* argv[]) { srand(7); plat_logf("SDL init"); SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(LCD_WIDTH, LCD_HEIGHT, 32, SDL_HWSURFACE | SDL_HWACCEL); SDL_EnableKeyRepeat(1, SDL_DEFAULT_REPEAT_INTERVAL); assert(screen != NULL); fgcol = LCD_RGBPACK(255,255,255); bgcol = LCD_RGBPACK(0,0,0); action = NONE; SDL_WM_SetCaption(GAME_TITLE, GAME_TITLE); atexit(SDL_Quit); plat_logf("TTF init"); if(TTF_Init() < 0) { plat_logf("TTF init fail!\n"); } gameover_font = TTF_OpenFont("/usr/share/fonts/TTF/LiberationSans-Regular.ttf", LCD_HEIGHT / 12); font = TTF_OpenFont("/usr/share/fonts/TTF/LiberationSans-Regular.ttf", LCD_HEIGHT / 24); if(!gameover_font) { plat_logf("WARNING: font loading failed"); } atexit(TTF_Quit); dash_main(); return 0; }
static void init() { // Start SDL if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 ) exit( EXIT_FAILURE ); atexit( SDL_Quit ); SDL_EnableKeyRepeat( 500, 80 ); // Init scope scope = new Audio_Scope; if ( !scope ) handle_error( "Out of memory" ); if ( scope->init( scope_width, 256 ) ) handle_error( "Couldn't initialize scope" ); memset( scope_buf, 0, sizeof scope_buf ); // Create player player = new Music_Player; if ( !player ) handle_error( "Out of memory" ); handle_error( player->init() ); player->set_scope_buffer( scope_buf, scope_width * 2 ); }
// // I_InitInput // bool I_InitInput (void) { if(Args.CheckParm("-nomouse")) { nomouse = true; } atterm (I_ShutdownInput); noidle = Args.CheckParm ("-noidle"); SDL_EnableUNICODE(true); // denis - disable key repeats as they mess with the mouse in XP SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); #ifdef WIN32 // denis - in fullscreen, prevent exit on accidental windows key press g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0); #endif return true; }
//Registers, creates, and shows the Window!! bool WinCreate() { const SDL_VideoInfo* video_info; int init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; if(SDL_Init(init_flags) < 0) { return false; } if(TTF_Init()<0) { return false; } SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(500, 25); atexit(SDL_Quit); SDL_WM_SetCaption("Cataclysm: Goon Days Ahead - 0.35 SDL", NULL); video_info = SDL_GetVideoInfo(); nativeWidth = video_info->current_w; nativeHeight = video_info->current_h; char center_string[] = "SDL_VIDEO_CENTERED=center"; // indirection needed to avoid a warning SDL_putenv(center_string); screen = SDL_SetVideoMode(WindowWidth, WindowHeight, 32, (SDL_SWSURFACE|SDL_DOUBLEBUF)); //SDL_SetColors(screen,windowsPalette,0,256); if(screen==NULL) return false; ClearScreen(); return true; };
// // I_InitInput // bool I_InitInput (void) { if(Args.CheckParm("-nomouse")) { nomouse = true; } atterm (I_ShutdownInput); SDL_EnableUNICODE(true); // denis - disable key repeats as they mess with the mouse in XP // mike - maybe not? //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL*2); // Initialize the joystick subsystem and open a joystick if use_joystick is enabled. -- Hyper_Eye Printf(PRINT_HIGH, "I_InitInput: Initializing SDL's joystick subsystem.\n"); SDL_InitSubSystem(SDL_INIT_JOYSTICK); if((int)use_joystick && I_GetJoystickCount()) { I_OpenJoystick(); EnableJoystickPolling(); } #ifdef WIN32 // denis - in fullscreen, prevent exit on accidental windows key press // [Russell] - Disabled because it screws with the mouse //g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0); #endif //CreateCursors(); UpdateFocus(); UpdateGrab(); return true; }
static void *main_thread(void *p) { if (GTK_TOGGLE_BUTTON(dynam)->active == 1) dynacore = 1; else if (GTK_TOGGLE_BUTTON(pure_interp)->active == 1) dynacore = 2; else dynacore = 0; SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(10, 10, 16, 0); SDL_SetEventFilter(filter); SDL_ShowCursor(0); SDL_EnableKeyRepeat(0, 0); init_memory(); plugin_load_plugins(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_gfx)->entry)), gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_audio)->entry)), gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_input)->entry)), gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_RSP)->entry))); romOpen_gfx(); romOpen_audio(); romOpen_input(); go(); romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); closeDLL_RSP(); closeDLL_input(); closeDLL_audio(); closeDLL_gfx(); free(rom); rom = NULL; free(ROM_HEADER); ROM_HEADER = NULL; free_memory(); file_selection_launched = 0; return 0; }
int OPENGL_mod::get_key() { SDL_Event event; SDL_EnableKeyRepeat(10,10); while (SDL_WaitEvent(&event)) { if(event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) return 27; else if (event.key.keysym.sym == SDLK_UP) return 260; else if (event.key.keysym.sym == SDLK_DOWN) return 261; else if (event.key.keysym.sym == SDLK_LEFT) return 259; else if (event.key.keysym.sym == SDLK_RIGHT) return 258; else return -1; } } }
bool Game::init(){ //initialises the random seed using the current timestamp srand(time(NULL)); //Loads the background image if(background.onLoad("./images/background.bmp", 1280,720,1)==false){ return false; } //loads the player image if(entity.onLoad("./images/player.bmp", 64,64,8)==false){ return false; } //pushes the background entity to the back of the Entity vector EntityList.push_back(&background); //pushes the player entity to the back of the Entity vector EntityList.push_back(&entity); //enables repeat keys so movement keys can be held down SDL_EnableKeyRepeat(1, SDL_DEFAULT_REPEAT_INTERVAL / 3); //returns true if initilisation was successful return true; }
void sdl_end() { extern t_sdl t; SDL_EnableKeyRepeat(0, 0); SDL_FreeSurface(t.mur); SDL_FreeSurface(t.echelle); SDL_FreeSurface(t.key_img); SDL_FreeSurface(t.end); SDL_FreeSurface(t.monstre); SDL_FreeSurface(t.coeur); for (t.i = 0 ; t.i < 4 ; t.i++) SDL_FreeSurface(t.mario[t.i]); if (t.flag == 2 && t.niveau == 4) win(1); if (t.flag == 2 && t.niveau != 4) { t.niveau++; getmap(t.lvl[t.niveau]); } if (t.flag == 3) win(2); SDL_Quit(); }
void init() { int status; signal(SIGINT, set_interrupted); signal(SIGTERM, set_interrupted); //if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) { if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) { fprintf(stderr, "Can't init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); status = TTF_Init(); if (status) { fprintf(stderr, "Can't init SDL_ttf\n"); exit(-1); } atexit(TTF_Quit); SDL_WM_SetCaption("NetWalk", "NetWalk"); SDL_EnableKeyRepeat(150, 50); }
//=========================================================================== int FrameCreateWindow () { ////************** Init SDL and create window screen // int xpos; // if (!RegLoadValue(TEXT("Preferences"),TEXT("Window X-Position"),1,(DWORD *)&xpos)) // xpos = (GetSystemMetrics(SM_CXSCREEN)-width) >> 1; // int ypos; // if (!RegLoadValue(TEXT("Preferences"),TEXT("Window Y-Position"),1,(DWORD *)&ypos)) // ypos = (GetSystemMetrics(SM_CYSCREEN)-height) >> 1; SDL_putenv("SDL_VIDEO_CENTERED=center"); //center our window bIamFullScreened = false; // at startup not in fullscreen mode screen = SDL_SetVideoMode(g_ScreenWidth, g_ScreenHeight, SCREEN_BPP, SDL_SWSURFACE | SDL_HWPALETTE); if (screen == NULL) { fprintf(stderr, "Could not set SDL video mode: %s\n", SDL_GetError()); SDL_Quit(); return 1; }//if // define if we have resized window g_WindowResized = (g_ScreenWidth != SCREEN_WIDTH) | (g_ScreenHeight != SCREEN_HEIGHT); printf("Screen size is %dx%d\n",g_ScreenWidth, g_ScreenHeight); if(g_WindowResized) { // create rects for screen stretching origRect.x = origRect.y = newRect.x = newRect.y = 0; origRect.w = SCREEN_WIDTH; origRect.h = SCREEN_HEIGHT; newRect.w = g_ScreenWidth; newRect.h = g_ScreenHeight; } // let us use keyrepeat? SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // // SDL_WM_SetCaption(g_pAppTitle, g_pAppTitle); // set caption for our window screen return 0; }
void ConfigureKeys::on_enter() { #ifndef DISABLE_LIBSIGC Globals g; SDL_EnableKeyRepeat(g.values().get(VAL_MENU_KEYREPEAT_DELAY), g.values().get(VAL_MENU_KEYREPEAT_INTERVAL)); create_key_map(); create_gui(); mb_grab_key = false; m_which_player = 0; m_bg = g.render().LoadTexture(g.images().background_random()); m_anim_bomb.SetAnimation(ANI_BOMB); m_anim_bomb.Start(); mp_keyconfig = &g.keycfg(); g.render().SetTextSizes(16, 16); #endif // DISABLE_LIBSIGC }
/* Initialise the input module */ void inputInitialise(void) { unsigned int i; for (i = 0; i < KEY_MAXSCAN; i++) { aKeyState[i].state = KEY_UP; } for (i = 0; i < 6; i++) { aMouseState[i].state = KEY_UP; } pStartBuffer = pInputBuffer; pEndBuffer = pInputBuffer; dragX = mouseXPos = screenWidth/2; dragY = mouseYPos = screenHeight/2; dragKey = MOUSE_LMB; SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); }
// This function performs all configuration necessary and returns the screen object SDL_Surface * DoConf(){ // TODO: make double buffering optional int params = SDL_HWSURFACE | SDL_SRCALPHA | SDL_DOUBLEBUF; if (RugConf.fullscreen){ params |= SDL_FULLSCREEN; } SDL_Surface * wnd = SDL_SetVideoMode(RugConf.width, RugConf.height, RugConf.bpp, params); if (RugConf.title != Qnil){ SDL_WM_SetCaption(STR2CSTR(RugConf.title), NULL); } SDL_ShowCursor(RugConf.show_cursor); if (RugConf.gui){ rb_eval_string("Rug::GUI.load"); } // enable key repeating SDL_EnableKeyRepeat(RugConf.repeatDelay, RugConf.repeatInterval); return wnd; }
const char *VideoDriver_SDL::Start(const char * const *parm) { char buf[30]; const char *s = SdlOpen(SDL_INIT_VIDEO); if (s != NULL) return s; GetVideoModes(); if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) { return SDL_CALL SDL_GetError(); } SDL_CALL SDL_VideoDriverName(buf, sizeof buf); DEBUG(driver, 1, "SDL: using driver '%s'", buf); MarkWholeScreenDirty(); SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_CALL SDL_EnableUNICODE(1); _draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL; return NULL; }
static void setup_sdl() { const SDL_VideoInfo* video; if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialise SDL: %s\n", SDL_GetError()); exit(1); } // Quit SDL properly on exit atexit(SDL_Quit); // Get current video information video = SDL_GetVideoInfo(); if (video == NULL) { fprintf(stderr, "Couldn't get video information %s\n", SDL_GetError()); exit(1); } // Set minimim requirements for the OpenGL window SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1); // Set title SDL_WM_SetCaption( "Totally Bananas?", NULL ); // Enable keyboard repeat SDL_EnableKeyRepeat(70, 70); if (SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_OPENGL | SDL_FULLSCREEN) == 0) { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); exit(1); } }
void Display::init(){ quit = false; sdlRect.x = 0; sdlRect.y = 0; sdlRect.w = 320; sdlRect.h = 240; imageCamera = cvCreateImage( cvSize(250, 250 ), IPL_DEPTH_8U, 3 ); SDL_EnableKeyRepeat(0,0); SDL_EnableUNICODE(1); SDL_WM_SetCaption("Window",NULL); SDL_ShowCursor(SDL_DISABLE); imageManualMode = SDL_LoadBMP("./Background/bgManualMode.bmp"); imageTrackingMode = SDL_LoadBMP("./Background/bgTrackingMode.bmp"); image = imageManualMode; SDL_BlitSurface(image, NULL, surface, &sdlRect); SDL_Flip(surface); }
// 初期化 int Core::Initialize(std::string title_ = "Title" , int width_ = DefaultWidth, int height_ = DefaultHeight, int SDLflags = SDL_OPENGL) { const SDL_VideoInfo* info = NULL; if (SDL_Init(SDL_INIT_VIDEO) < 0) { Logger::Instance()->OutputString("Error: " + std::string(SDL_GetError())); return -1; } Logger::Instance()->OutputString("SDL_Init succeeded"); title = title_; SDL_WM_SetCaption(title.c_str(), NULL); info = SDL_GetVideoInfo( ); if (!info) { Logger::Instance()->OutputString("Error: " + std::string(SDL_GetError())); return -1; } Logger::Instance()->OutputString("SDL_GetVideoInfo succeeded"); bpp = info->vfmt->BitsPerPixel; // 適当です SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); width = width_; height = height_; if (SDL_SetVideoMode(width, height, bpp, SDLflags) == 0) { Logger::Instance()->OutputString("Error: " + std::string(SDL_GetError())); return -1; } Logger::Instance()->OutputString("SDL_SetVideoMode succeeded"); #ifdef __WIN32__ // GLEW if (glewInit() != GLEW_OK) { Logger::Instance()->OutputString("Error: glewInit()"); return -1; } Logger::Instance()->OutputString("glewInit succeeded"); #endif __WIN32__ // オプションのテクスチャ glGenTextures(1, &optionTexture); SDL_Surface* bmp = SDL_LoadBMP("option.bmp"); if (bmp != NULL) { Uint32 rmask, gmask, bmask, amask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif SDL_Surface* tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, bmp->w, bmp->h, 32, rmask, gmask, bmask, amask); SDL_Rect rect; rect.x = rect.y = 0; rect.w = bmp->w; rect.h = bmp->h; SDL_BlitSurface(bmp, &rect, tmp, &rect); SDL_LockSurface(tmp); //glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, optionTexture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmp->w, bmp->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //glActiveTexture(GL_TEXTURE0); SDL_UnlockSurface(tmp); SDL_FreeSurface(tmp); SDL_FreeSurface(bmp); } else { Logger::Instance()->OutputString("Error: SDL_LoadBMP"); } frameBuffer = 0; renderBuffer = 0; renderTexture = 0; glGenFramebuffers(1, &frameBuffer); glGenRenderbuffers(1, &renderBuffer); glGenTextures(1, &renderTexture); // フレームバッファ glBindTexture(GL_TEXTURE_2D, renderTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTexture, 0); // レンダーバッファ glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBuffer); // glBindTexture(GL_TEXTURE_2D, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); SDL_EnableUNICODE(true); SDL_EnableKeyRepeat(250, 25); errorHighlight = true; return 0; }
static SDL_Overlay * video_init( void *data, SDL_Surface **pscreen ) { struct ALL_DATA *all_data = (struct ALL_DATA *) data; struct GLOBAL *global = all_data->global; int width = global->width; int height = global->height; if (*pscreen == NULL) //init SDL { char driver[128]; /*----------------------------- Test SDL capabilities ---------------------*/ if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) { g_printerr("Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } /* For this version, we will use hardware acceleration as default*/ if(global->hwaccel) // set global environmental variables if hw accel available { if ( ! getenv("SDL_VIDEO_YUV_HWACCEL") ) putenv("SDL_VIDEO_YUV_HWACCEL=1"); if ( ! getenv("SDL_VIDEO_YUV_DIRECT") ) putenv("SDL_VIDEO_YUV_DIRECT=1"); } else { if ( ! getenv("SDL_VIDEO_YUV_HWACCEL") ) putenv("SDL_VIDEO_YUV_HWACCEL=0"); if ( ! getenv("SDL_VIDEO_YUV_DIRECT") ) putenv("SDL_VIDEO_YUV_DIRECT=0"); } // print the name of the video driver if debugging if (SDL_VideoDriverName(driver, sizeof(driver)) && global->debug) { g_print("Video driver: %s\n", driver); } info = SDL_GetVideoInfo(); // get camera info if (info->wm_available && global->debug) g_print("A window manager is available\n"); if (info->hw_available) { if (global->debug) g_print("Hardware surfaces are available (%dK video memory)\n", info->video_mem); SDL_VIDEO_Flags |= SDL_HWSURFACE; SDL_VIDEO_Flags |= SDL_DOUBLEBUF; } else { SDL_VIDEO_Flags |= SDL_SWSURFACE; } if (info->blit_hw) { if (global->debug) g_print("Copy blits between hardware surfaces are accelerated\n"); SDL_VIDEO_Flags |= SDL_ASYNCBLIT; } if(!global->desktop_w) global->desktop_w = info->current_w; //get desktop width if(!global->desktop_h) global->desktop_h = info->current_h; //get desktop height if (global->debug) { if (info->blit_hw_CC) g_print ("Colorkey blits between hardware surfaces are accelerated\n"); if (info->blit_hw_A) g_print("Alpha blits between hardware surfaces are accelerated\n"); if (info->blit_sw) g_print ("Copy blits from software surfaces to hardware surfaces are accelerated\n"); if (info->blit_sw_CC) g_print ("Colorkey blits from software surfaces to hardware surfaces are accelerated\n"); if (info->blit_sw_A) g_print("Alpha blits from software surfaces to hardware surfaces are accelerated\n"); if (info->blit_fill) g_print("Color fills on hardware surfaces are accelerated\n"); } SDL_WM_SetCaption(global->WVcaption, NULL); /* enable key repeat */ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); } /*------------------------------ SDL init video ---------------------*/ if(global->debug) g_print("(Desktop resolution = %ix%i)\n", global->desktop_w, global->desktop_h); g_print("Checking video mode %ix%[email protected] : ", width, height); int bpp = SDL_VideoModeOK( width, height, 32, SDL_VIDEO_Flags); if(!bpp) { g_print("Not available \n"); /*resize video mode*/ if ((width > global->desktop_w) || (height > global->desktop_h)) { width = global->desktop_w; /*use desktop video resolution*/ height = global->desktop_h; } else { width = 800; height = 600; } g_print("Resizing to %ix%i\n", width, height); } else // success: { g_print("OK \n"); if ((bpp != 32) && global->debug) g_print("recomended color depth = %i\n", bpp); global->bpp = bpp; } *pscreen = SDL_SetVideoMode( width, height, global->bpp, SDL_VIDEO_Flags); if(*pscreen == NULL) { return (NULL); } //use requested resolution for overlay even if not available as video mode SDL_Overlay* overlay=NULL; overlay = SDL_CreateYUVOverlay(global->width, global->height, SDL_YUY2_OVERLAY, *pscreen); SDL_ShowCursor(SDL_DISABLE); return (overlay); }
void VideoDriver_SDL::SetupKeyboard() { SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_CALL SDL_EnableUNICODE(1); }