static void init_sdl() { SDL_putenv("SDL_NOMOUSE=1"); SDL_putenv("SDL_VIDEO_CENTERED=1"); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE); atexit(SDL_Quit); signal(SIGINT, SIG_DFL); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_AudioSpec desired = {.freq = 8000, .format = AUDIO_U8, .channels = 1, .callback = snd_callback, .samples=128}; if(SDL_OpenAudio(&desired, NULL)) { fprintf(stderr, "%s\n", SDL_GetError()); sound_playing = -1; } SDL_initFramerate(&fps); SDL_setFramerate(&fps, 60); inited_sdl = 1; } static void button_change(int up, SDLKey keysym) { const uint32_t key_map[SDLK_LAST] = { [SDLK_LEFT] = KEY_LF, [SDLK_RIGHT] = KEY_RT, [SDLK_UP] = KEY_UP, [SDLK_DOWN] = KEY_DN, [SDLK_RETURN] = KEY_A, [SDLK_SPACE] = KEY_A, [SDLK_z] = KEY_A, [SDLK_x] = KEY_B, [SDLK_LSHIFT] = KEY_B, [SDLK_RSHIFT] = KEY_A }; /* Don't invoke undefined behavior if they've added keysyms * since this was compiled. */ if(keysym > SDLK_LAST) return; if(!key_map[keysym]) return; if(up) { buttons &= ~key_map[keysym]; } else { buttons |= key_map[keysym]; } }
/** * Sets up all the internal display flags depending on * the current video settings. */ void Screen::makeVideoFlags() { _flags = SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_HWPALETTE; if (Options::asyncBlit) { _flags |= SDL_ASYNCBLIT; } if (isOpenGLEnabled()) { _flags = SDL_OPENGL; 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 ); } if (Options::allowResize) { _flags |= SDL_RESIZABLE; } // Handle window positioning if (Options::windowedModePositionX != -1 || Options::windowedModePositionY != -1) { std::ostringstream ss; ss << "SDL_VIDEO_WINDOW_POS=" << std::dec << Options::windowedModePositionX << "," << Options::windowedModePositionY; SDL_putenv(const_cast<char*>(ss.str().c_str())); SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=")); } else if (Options::borderless) { SDL_putenv(const_cast<char*>("SDL_VIDEO_WINDOW_POS=")); SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")); } else { SDL_putenv(const_cast<char*>("SDL_VIDEO_WINDOW_POS=")); SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=")); } // Handle display mode if (Options::fullscreen) { _flags |= SDL_FULLSCREEN; } if (Options::borderless) { _flags |= SDL_NOFRAME; SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")); } else { SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=")); } _bpp = (is32bitEnabled() || isOpenGLEnabled()) ? 32 : 8; _baseWidth = Options::baseXResolution; _baseHeight = Options::baseYResolution; }
int OglInitWindow (int w, int h, int bForce) { int bRebuild = 0; GLint i; if (gameStates.ogl.bInitialized) { if (!bForce && (w == nCurWidth) && (h == nCurHeight) && (bCurFullScr == gameStates.ogl.bFullScreen)) return -1; if ((w != nCurWidth) || (h != nCurHeight) || (bCurFullScr != gameStates.ogl.bFullScreen)) { OglSmashTextureListInternal ();//if we are or were fullscreen, changing vid mode will invalidate current textures bRebuild = 1; } } if (w < 0) w = nCurWidth; if (h < 0) h = nCurHeight; if ((w < 0) || (h < 0)) return -1; D2SetCaption (); OglInitAttributes (); /***/LogErr ("setting SDL video mode (%dx%dx%d, %s)\n", w, h, gameStates.ogl.nColorBits, gameStates.ogl.bFullScreen ? "fullscreen" : "windowed"); #if 1//def RELEASE SDL_putenv ("SDL_VIDEO_CENTERED=1"); #endif if (!OglVideoModeOK (w, h) || !SDL_SetVideoMode (w, h, gameStates.ogl.nColorBits, SDL_VIDEO_FLAGS)) { Error ("Could not set %dx%dx%d opengl video mode\n", w, h, gameStates.ogl.nColorBits); return 0; } gameStates.ogl.nColorBits = 0; glGetIntegerv (GL_RED_BITS, &i); gameStates.ogl.nColorBits += i; glGetIntegerv (GL_GREEN_BITS, &i); gameStates.ogl.nColorBits += i; glGetIntegerv (GL_BLUE_BITS, &i); gameStates.ogl.nColorBits += i; glGetIntegerv (GL_ALPHA_BITS, &i); gameStates.ogl.nColorBits += i; glGetIntegerv (GL_DEPTH_BITS, &gameStates.ogl.nDepthBits); glGetIntegerv (GL_STENCIL_BITS, &gameStates.ogl.nStencilBits); gameStates.render.bHaveStencilBuffer = (gameStates.ogl.nStencilBits > 0); SDL_ShowCursor (0); nCurWidth = w; nCurHeight = h; bCurFullScr = gameStates.ogl.bFullScreen; if (gameStates.ogl.bInitialized && bRebuild) { glViewport (0, 0, w, h); if (gameStates.app.bGameRunning) { GrPaletteStepLoad (NULL); RebuildGfxFx (1, 1); } else GrRemapMonoFonts (); //FreeInventoryIcons (); } gameStates.ogl.bInitialized = 1; return 1; }
Manager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), io( IOManager::getInstance() ), clock( Clock::getInstance() ), screen( io.getScreen() ), world("back", Gamedata::getInstance().getXmlInt("back/factor") ), world2("back2", Gamedata::getInstance().getXmlInt("back2/factor") ), viewport( Viewport::getInstance() ), sprites(), currentSprite(0), makeVideo( false ), frameCount( 0 ), username( Gamedata::getInstance().getXmlStr("username") ), title( Gamedata::getInstance().getXmlStr("screenTitle") ), frameMax( Gamedata::getInstance().getXmlInt("frameMax") ) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } SDL_WM_SetCaption(title.c_str(), NULL); atexit(SDL_Quit); sprites.push_back( new Hero("pet2") ); sprites.push_back( new Hero("pet4") ); sprites.push_back( new TwoWayMultiSprite("pet1") ); sprites.push_back( new TwoWayMultiSprite("pet3") ); sprites.push_back( new Sprite("ufo") ); dynamic_cast<Hero*>(sprites[0])->addSpecialEffect(new MultiSprite("sp2")); dynamic_cast<Hero*>(sprites[1])->addSpecialEffect(new MultiSprite("sp1")); viewport.setObjectToTrack(sprites[currentSprite]); }
void initGUI () { // Initialise SDL library if (SDL_Init (SDL_INIT_VIDEO) == -1) { throw "Error loading SDL"; } // Initialise SDL_ttf if (TTF_Init () == -1) { throw "Error loading SDL_ttf"; } // Set SDL settings // Make window open at the centre of the screen SDL_putenv ((char*)"SDL_VIDEO_WINDOW_POS=center"); // Set window caption SDL_WM_SetCaption (WINDOW_NAME, NULL); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); // Set up screen screen = SDL_SetVideoMode (DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_BPP, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE); if (screen == NULL) { throw "Error while setting up SDL"; } }
bool Graphics::InitSDL() { // Init video if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { std::cout << "Couldn't initialize SDL: " << SDL_GetError() << std::endl; SDL_Quit(); return false; } // Set window position to center SDL_putenv((char*)"SDL_VIDEO_CENTERED=center"); // Set video mode if ((mScreen = SDL_SetVideoMode(mScreenWidth, mScreenHeight, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL)) == NULL) { std::cout << "Couldn't set " << mScreenWidth << "x" << mScreenHeight << " video mode: " << SDL_GetError() << std::endl; SDL_Quit(); return false; } std::cout << "SDL initialization OK\n"; return true; }
int ui_init() { int width, height; font_init(); width = config_get_int("width"); height = config_get_int("height"); SDL_putenv("SDL_VIDEO_WINDOW_POS=center"); if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); return -1; } atexit(SDL_Quit); screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); if (screen == NULL) { fprintf(stderr, "Unable to set %dx%d video: %s\n", width, height, SDL_GetError()); return -1; } scripting_init_ui(); SDL_Flip(screen); return 0; }
static void set_video_mode() { int flags = 0; #ifndef HAVE_GLES flags |= SDL_DOUBLEBUF; flags |= SDL_OPENGL; #endif if (g_fs_emu_video_fullscreen == 1) { g_fs_ml_video_width = g_fullscreen_width; g_fs_ml_video_height = g_fullscreen_height; if (g_fs_emu_video_fullscreen_window) { fs_log("using fullscreen window mode\n"); SDL_putenv("SDL_VIDEO_WINDOW_POS=0,0"); flags |= SDL_NOFRAME; fs_ml_set_fullscreen_extra(); } else { fs_log("using SDL_FULLSCREEN mode\n"); flags |= SDL_FULLSCREEN; } fs_log("setting (fullscreen) video mode %d %d\n", g_fs_ml_video_width, g_fs_ml_video_height); g_sdl_screen = SDL_SetVideoMode(g_fs_ml_video_width, g_fs_ml_video_height, 0, flags); //update_viewport(); } else { fs_log("using windowed mode\n"); SDL_putenv("SDL_VIDEO_WINDOW_POS="); g_fs_ml_video_width = g_window_width; g_fs_ml_video_height = g_window_height; if (g_window_resizable) { flags |= SDL_RESIZABLE; } fs_log("setting (windowed) video mode %d %d\n", g_fs_ml_video_width, g_fs_ml_video_height); g_sdl_screen = SDL_SetVideoMode(g_fs_ml_video_width, g_fs_ml_video_height, 0, flags); //update_viewport(); } fs_ml_configure_window(); // FIXME: this can be removed g_fs_ml_opengl_context_stamp++; log_opengl_information(); }
void init_win32() { SDL_Cursor *cursor = SDL_GetCursor(); HINSTANCE handle = GetModuleHandle(NULL); //((struct zWMcursor *)cursor->wm_cursor)->curs = (void *)LoadCursorA(NULL, IDC_ARROW); ((struct zWMcursor *)cursor->wm_cursor)->curs = (void *)LoadCursor(NULL, IDC_ARROW); SDL_SetCursor(cursor); icon = LoadIcon(handle, (char *)101); SDL_GetWMInfo(&wminfo); hwnd = wminfo.window; SetClassLong(hwnd, GCL_HICON, (LONG)icon); SDL_putenv("SDL_VIDEO_WINDOW_POS=center"); SDL_putenv("SDL_VIDEO_CENTERED=center"); }
int main(int argc, char **argv) { if (!SDL_getenv("SDL_AUDIODRIVER")) { SDL_putenv("SDL_AUDIODRIVER=waveout"); } return game_main(argc, argv); }
int Display_SDL::CreateScreen(int x0, int y0, int w, int h, Uint32 nFlags) { char pc[256] = "SDL_VIDEO_CENTERED=1"; //sprintf(pc, "SDL_VIDEO_CENTERED", x0, y0); //g_pErr->Report("NO!"); SDL_putenv(pc); m_pScreen = SDL_SetVideoMode(w, h, 0, nFlags); StimulusBmp::SetScreen(m_pScreen); m_bSelfAlloc = true; }
Manager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), io( IOManager::getInstance() ), clock( Clock::getInstance() ), screen( io.getScreen() ), world("back"), viewport( Viewport::getInstance() ), sprites(), currentSprite(), makeVideo( false ), frameCount( 0 ), username( Gamedata::getInstance().getXmlStr("username") ), title( Gamedata::getInstance().getXmlStr("screenTitle") ), frameMax( Gamedata::getInstance().getXmlInt("frameMax") ), eachSpritsNumbe() { if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } SDL_WM_SetCaption(title.c_str(), NULL); atexit(SDL_Quit); sprites.push_back( new TwoWaySprite("Gundam")); eachSpritsNumbe.push_back(Gamedata::getInstance().getXmlInt("Gundam/number")); eachSpritsNumbe.push_back(Gamedata::getInstance().getXmlInt("Enemy/number")); eachSpritsNumbe.push_back(Gamedata::getInstance().getXmlInt("Vessel1/number")); eachSpritsNumbe.push_back(Gamedata::getInstance().getXmlInt("Explotion/number")); for (int i = 0; i< eachSpritsNumbe[1]; i++) { sprites.push_back( new Enemy("Enemy")); } for (int i=0; i< eachSpritsNumbe[2]; i++) { sprites.push_back( new Vessel("Vessel1") ); } for (int i=0; i< eachSpritsNumbe[3]; i++) { sprites.push_back( new Explotion("Explotion") ); } currentSprite = sprites.begin(); viewport.setObjectToTrack(*currentSprite); }
Manager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), gdata( Gamedata::getInstance() ), io( IOManager::getInstance() ), frameFactory( FrameFactory::getInstance() ), clock( Clock::getInstance() ), smanager(), screen( io.getScreen() ), backgroundWorld(const_cast<Frame*>(frameFactory->getFrame("background","background")[0]),6), parallaxWorld1(const_cast<Frame*>(frameFactory->getFrame("parallax1","parallax")[0]),5), parallaxWorld2(const_cast<Frame*>(frameFactory->getFrame("parallax2","parallax")[0]),4), parallaxWorld3(const_cast<Frame*>(frameFactory->getFrame("parallax3","parallax")[0]),3), parallaxWorld4(const_cast<Frame*>(frameFactory->getFrame("parallax4","parallax")[0]),2), parallaxWorld5(const_cast<Frame*>(frameFactory->getFrame("parallax5","parallax")[0]),1), viewport( Viewport::getInstance() ), orbs(), characters(), asteroids(), opponents(), ai(), explosions(), collisionStrategy( new MidPointCollisionStrategy ), currentOrb(0), helpFlag(false), done(false), rightFlag(false), aishootflag(false), gameoverflag(false), gamewon(false), score(0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } characters.push_back(MultiframeSprite("player1","player",smanager)); for (int i = 0; i < 15; i++){ asteroids.push_back(new MultiframeSprite("asteroid","asteroid",smanager)); } for (int i = 0; i < 10; i++){ opponents.push_back(new MultiframeSprite("opponent","asteroid",smanager)); } for (int i = 0; i < 1; i++){ ai.push_back(new MultiframeSprite("ai","player",smanager)); } viewport.setObjectToTrack(&characters[currentOrb]); atexit(SDL_Quit); }
Manager::Manager() : bar(), gameOver(false), level(2), explosionInterval(Gamedata::getInstance().getXmlInt("NoKillInterval")), timeSinceLastExplosion(0), env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), io( IOManager::getInstance() ), clock( Clock::getInstance() ), screen( io.getScreen() ), world1("back", Gamedata::getInstance().getXmlInt("backFactor") ), world2("back1", Gamedata::getInstance().getXmlInt("back1Factor") ), viewport( Viewport::getInstance() ), sprites(), Rainsprites(), parachutes(), cachePlayer(new Player("Jet")), blast(new MultiSprite("blast")), myPlayer(cachePlayer), explosion(false), cacheEnemies(), enemyBlasts(), enemies(), enemyExploded(), bullets("bullet"), currentSprite(0), showHelp(false), showHUD(true) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) { throw string("Unable to initialize SDL: "); } atexit(SDL_Quit); //sprites.push_back( new TwoWayMultiSprite("Jet") ); //Player myPlayer = new Player("Jet"); for(unsigned int i =0; i<5000 ; i++) Rainsprites.push_back( new Rain("smallrain") ); for(unsigned int i =0; i<1000 ; i++) Rainsprites.push_back( new Rain("bigrain") ); //sprites.push_back( myPlayer ); sprites.push_back( new TwoWayMultiSprite("tanks") ); sprites.push_back( new Sprite("logo") ); //viewport.setObjectToTrack(sprites[currentSprite]); //viewport.setObjectToTrack(sprites[1]); viewport.setObjectToTrack(myPlayer); clock.pause(); }
/** * Initializes a new display screen for the game to render contents to. * @param width Width in pixels. * @param height Height in pixels. * @param bpp Bits-per-pixel. * @param fullscreen Fullscreen mode. * @warning Currently the game is designed for 8bpp, so there's no telling what'll * happen if you use a different value. */ Screen::Screen(int width, int height, int bpp, bool fullscreen, int windowedModePositionX, int windowedModePositionY) : _bpp(bpp), _scaleX(1.0), _scaleY(1.0), _fullscreen(fullscreen), _numColors(0), _firstColor(0), _surface(0) { char *prev; if (!_fullscreen && (windowedModePositionX != -1 || windowedModePositionY != -1)) { prev = SDL_getenv("SDL_VIDEO_WINDOW_POS"); if (0 == prev) prev = (char*)""; std::stringstream ss; ss << "SDL_VIDEO_WINDOW_POS=" << std::dec << windowedModePositionX << "," << windowedModePositionY; SDL_putenv(const_cast<char*>(ss.str().c_str())); } setResolution(width, height); if (!_fullscreen && (windowedModePositionX != -1 || windowedModePositionY != -1)) { // We don't want to put the window back to the starting position later when the window is resized. std::stringstream ss; ss << "SDL_VIDEO_WINDOW_POS=" << prev; SDL_putenv(const_cast<char*>(ss.str().c_str())); } memset(deferredPalette, 0, 256*sizeof(SDL_Color)); }
void MainWindow::HideSDLWindow(void) { QWidget *widget=new QWidget; char winID[32] = {0}; sprintf(winID, "SDL_WINDOWID=0x%lx", (long unsigned int)widget->winId()); SDL_putenv(winID); widget->hide(); }
//Registers, creates, and shows the Window!! bool WinCreate() { 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_InitSubSystem(SDL_INIT_JOYSTICK); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(500, OPTIONS["INPUT_DELAY"]); 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"] != "show" && SDL_ShowCursor(-1)) SDL_ShowCursor(SDL_DISABLE); else SDL_ShowCursor(SDL_ENABLE); // Initialize joysticks. int numjoy = SDL_NumJoysticks(); if(numjoy > 1) { DebugLog() << "You have more than one gamepads/joysticks plugged in, only the first will be used.\n"; } if(numjoy >= 1) { joystick = SDL_JoystickOpen(0); } else { joystick = NULL; } SDL_JoystickEventState(SDL_ENABLE); return true; };
int main(int argc, char *argv[]){ #ifndef _WIN32 SDL_putenv("DINGOO_IGNORE_OS_EVENTS=1"); //HACK to fix "push long time on X" problem #endif if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Failed to initialize video: %s\n", SDL_GetError()); exit(-1); } atexit(SDL_Quit); #ifdef _WIN32 SDL_putenv("SDL_VIDEO_WINDOW_POS=300,200"); SDL_WM_SetCaption("Vectrex SDL", "Vectrex SDL"); resize(240, 320, 0); #else resize(320, 240, 1); #endif #ifdef _WIN32 if (argc > 1) cartfilename = argv[1]; #else if (stricmp(argv[0], "ROM.VECX") != 0) // If user selected ROM.VECX cartridge then don't use any cartridge { cartfilename = argv[0]; // In SIM files argv[0] contains the target to be loaded. } #endif init(); e8910_init_sound(); osint_emuloop(); e8910_done_sound(); SDL_Quit(); return 0; }
void display_init (Display* display, GLfloat near_plane, GLfloat far_plane, Args* args) { memset(display, 0, sizeof(Display)); display->near_plane = near_plane; display->far_plane = far_plane; #ifndef _WIN32 // avoid crash on EeePC's Xandros if (NULL == SDL_getenv ("SDL_VIDEO_X11_WMCLASS")) SDL_putenv ("SDL_VIDEO_X11_WMCLASS=cave9"); #endif Uint32 flags = SDL_INIT_VIDEO; if (!args->nosound) flags |= SDL_INIT_AUDIO; if (SDL_Init (flags) != 0) { fprintf (stderr, "SDL_Init(): %s\n", SDL_GetError()); exit (1); } atexit(SDL_Quit); const char* icon_file = FIND (ICON_FILE); display->icon = IMG_Load(icon_file); if(display->icon == NULL) { fprintf(stderr, "IMG_Load(%s): %s\n", icon_file, IMG_GetError()); exit(1); } int w = args->width; int h = args->height; int f = args->fullscreen; if(args->highres) { #if SDL_VERSION_ATLEAST(1,2,11) const SDL_VideoInfo* info = SDL_GetVideoInfo(); assert(info != NULL); w = info->current_w; h = info->current_h; #else w = BASE_W; h = BASE_H; #endif f = 1; } viewport(display, w, h, args->bpp, f, args->antialiasing, args->lighting); if(TTF_Init() != 0) { fprintf(stderr, "TTF_Init(): %s\n", TTF_GetError()); exit(1); } atexit(TTF_Quit); }
Manager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), io( IOManager::getInstance() ), clock( Clock::getInstance() ), screen( io.getScreen() ), world(NULL), world1("back1", Gamedata::getInstance().getXmlInt("back1Factor") ), viewport( Viewport::getInstance() ), sprites(), currentSprite(0), sprite_n(Gamedata::getInstance().getXmlInt("Sprit_N")), F1_help(false), player(), explodingPlayer(&player), thePlayer(&player), yue("yue"), FPS(Gamedata::getInstance().getXmlInt("FRAMES_PER_SECOND")), hud(), shootingSword("sword"), enemy(new MultiSprite("enemy")), // REMEMBER to free this explodingEnemy(new ExplodingSprite(*enemy)), // remember to free this theEnemy(enemy), life(NULL), lifeValue(200) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } atexit(SDL_Quit); // set the default background world = new World("back3", Gamedata::getInstance().getXmlInt("back3Factor") ); life = new Health(lifeValue); sprites.push_back(new MultiSprite("sun")); Vector2f pos = sprites[0]->getPosition(); Sprite * tmp = static_cast<Sprite*>( sprites[0] ); for (int i = 1; i < sprite_n; i++) { sprites.push_back( new SmartSprite("goldcoin30", pos, *tmp )); } sprites.push_back( player.getcurrent() ); currentSprite = sprites.size() - 1; viewport.setObjectToTrack(sprites[currentSprite]); enemy->setStatus(ENEMY); yue.setStatus(PAUSE); }
//-------------------------------------------------------------------------------------------- SDL_bool SDLX_set_sdl_gl_attrib( SDLX_video_parameters_t * v ) { if ( NULL == v ) return SDL_FALSE; if ( v->flags.opengl ) { SDLX_sdl_gl_attrib_t * patt = &( v->gl_att ); #if !defined(__unix__) // Under Unix we cannot specify these, we just get whatever format // the framebuffer has, specifying depths > the framebuffer one // will cause SDL_SetVideoMode to fail with: "Unable to set video mode: Couldn't find matching GLX visual" SDL_GL_SetAttribute( SDL_GL_RED_SIZE, patt->color[0] ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, patt->color[1] ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, patt->color[2] ); SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, patt->color[3] ); SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, patt->buffer_size ); #endif SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, patt->doublebuffer ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, patt->depth_size ); SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, patt->stencil_size ); SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, patt->accum[0] ); SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, patt->accum[1] ); SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, patt->accum[2] ); SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, patt->accum[3] ); SDL_GL_SetAttribute( SDL_GL_STEREO, patt->stereo ); #if defined(__unix__) // Fedora 7 doesn't suuport SDL_GL_SWAP_CONTROL, but we use this nvidia extension instead. if ( patt->swap_control ) { SDL_putenv( "__GL_SYNC_TO_VBLANK=1" ); } #else SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, patt->multi_buffers ); SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, patt->multi_samples ); SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, patt->accelerated_visual ); SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, patt->swap_control ); #endif } return SDL_TRUE; }
void Engine::initializeSDL() { std::clog << "Initializing SDL...\n"; if (SDL_Init(SDL_INIT_VIDEO) < 0) { throw EngineError("Could not initialize SDL", SDL_GetError()); } /* Some video inforamtion */ const SDL_VideoInfo *info = SDL_GetVideoInfo(); if (!info) { throw EngineError("Video query failed", SDL_GetError()); } int screen_bpp = info->vfmt->BitsPerPixel; 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); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); char env[] = "SDL_VIDEO_CENTERED=center"; SDL_putenv(env); int screen_flags = SDL_OPENGL; if (m_screenFull) screen_flags |= SDL_FULLSCREEN; std::clog << "Screen: " << m_screenWidth << "x" << m_screenHeight << "x" << screen_bpp << "\n"; // Screen surface SDL_Surface *screen = SDL_SetVideoMode(m_screenWidth, m_screenHeight, screen_bpp, screen_flags); if (!screen) { throw EngineError("Setting video mode failed", SDL_GetError()); } SDL_ShowCursor(SDL_DISABLE); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); std::clog << "SDL initialized.\n"; }
MenuManager::MenuManager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), screen( IOManager::getInstance().getScreen() ), clock( Clock::getInstance() ), backColor(), menu(), numberOfSprites(1) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } backColor.r = Gamedata::getInstance().getXmlInt("back/red"); backColor.g = Gamedata::getInstance().getXmlInt("back/green"); backColor.b = Gamedata::getInstance().getXmlInt("back/blue"); atexit(SDL_Quit); }
static void PostProcessGameArg() { if (CGameArg.SysMaxFPS < MINIMUM_FPS) CGameArg.SysMaxFPS = MINIMUM_FPS; else if (CGameArg.SysMaxFPS > MAXIMUM_FPS) CGameArg.SysMaxFPS = MAXIMUM_FPS; #if PHYSFS_VER_MAJOR >= 2 if (!CGameArg.SysMissionDir.empty()) PHYSFS_mount(CGameArg.SysMissionDir.c_str(), MISSION_DIR, 1); #endif static char sdl_disable_lock_keys[] = "SDL_DISABLE_LOCK_KEYS=0"; if (CGameArg.CtlNoStickyKeys) // Must happen before SDL_Init! sdl_disable_lock_keys[sizeof(sdl_disable_lock_keys) - 2] = '1'; SDL_putenv(sdl_disable_lock_keys); }
Manager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), jgdata( JSONGamedata::getInstance() ), io( IOManager::getInstance() ), clock( Clock::getInstance() ), screen( io.getScreen() ), worlds(), viewport( Viewport::getInstance() ), explosions(), sprites(), player(jgdata.getStr("player.name")), currentSprite(0), TICK_INTERVAL(jgdata.getInt("fpsController.tickInterval")), nextTime(clock.getTicks()+TICK_INTERVAL) { clock.pause(); if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } atexit(SDL_Quit); JSONValue* backs = jgdata.getValue("backgrounds"); unsigned int numbacks = backs->CountChildren(); std::cout << "Loading " << numbacks << " backgrounds" << std::endl; for(unsigned i = 0; i < numbacks; i++){ std::string name = backs->Child(i)->Child("name")->AsString(); int fact = 1; if (backs->Child(i)->HasChild("fact")) fact = backs->Child(i)->Child("fact")->AsNumber(); worlds.push_back( World(FrameFactory::getInstance().getFrame(name), fact) ); } unsigned int n = jgdata.getInt("triForce.num"); float smin = jgdata.getFloat("triForce.scale.min"); float smax = jgdata.getFloat("triForce.scale.max"); sprites.reserve(n+2); for(unsigned i = 0; i < n; i++){ sprites.push_back(new Sprite("triForce",smin,smax)); } explosions.push_back(new TwowayMultiframeSprite("Etank")); sort(sprites.begin(), sprites.end()); viewport.setObjectToTrack(player.getSprite()); }
bool View::initGUI() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { return false; } atexit(SDL_Quit); char envContents1[] = "SDL_VIDEO_CENTERED=1"; SDL_putenv(envContents1); screenSurface = SDL_SetVideoMode(modeX, modeY, 32, VIDEOFLAG); if (screenSurface == NULL) { return false; } SDL_WM_SetCaption("CellSim - Dundee iGEM 2012 - Christopher Walker", NULL); return true; }
//Registers, creates, and shows the Window!! bool WinCreate() { 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); //Flags used for setting up SDL VideoMode int screen_flags = SDL_SWSURFACE | SDL_DOUBLEBUF; //If FULLSCREEN was selected in options add SDL_FULLSCREEN flag to screen_flags, causing screen to go fullscreen. if(OPTIONS["FULLSCREEN"]) { screen_flags = screen_flags | SDL_FULLSCREEN; } screen = SDL_SetVideoMode(WindowWidth, WindowHeight, 32, screen_flags); //SDL_SetColors(screen,windowsPalette,0,256); if (screen == NULL) return false; ClearScreen(); if(OPTIONS["HIDE_CURSOR"] != "show" && SDL_ShowCursor(-1)) SDL_ShowCursor(SDL_DISABLE); else SDL_ShowCursor(SDL_ENABLE); // Initialize joysticks. int numjoy = SDL_NumJoysticks(); if(numjoy > 1) { DebugLog() << "You have more than one gamepads/joysticks plugged in, only the first will be used.\n"; } if(numjoy >= 1) { joystick = SDL_JoystickOpen(0); } else { joystick = NULL; } SDL_JoystickEventState(SDL_ENABLE); return true; };
EC_U32 SDL_VideoRender::Init(MediaCtxInfo* pMediaInfo, EC_U32 nScreenWidth, EC_U32 nScreenHight, EC_VOIDP pDrawable) { if (EC_NULL == pMediaInfo) return EC_Err_BadParam; AVCodecContext *pCodecCtx = (AVCodecContext*)(pMediaInfo->m_pVideoCodecInfo); if ((0 == nScreenWidth) || (0 == nScreenHight)) { nScreenWidth = pCodecCtx->width; nScreenHight = pCodecCtx->height; } m_pDrawable = pDrawable; char pEnvStr[256] = { 0 }; sprintf_s(pEnvStr, 255, "SDL_WINDOWID=0x%lx", pDrawable); SDL_putenv(pEnvStr); if (SDL_Init(SDL_INIT_VIDEO) < 0) return Video_Render_Err_InitFail; m_nWindowWidth = nScreenWidth; m_nWindowHeight = nScreenHight; m_nVideoWidth = pCodecCtx->width; m_nVideoHeight = pCodecCtx->height; m_nScreenWidth = GetSystemMetrics(SM_CXSCREEN); m_nScreenHeight = GetSystemMetrics(SM_CYSCREEN); EC_U32 nFlag = 0; if (m_pDrawable == EC_NULL) nFlag = SDL_FULLSCREEN; m_pScreen = SDL_SetVideoMode(m_nScreenWidth, m_nScreenHeight, 0, nFlag); if (EC_NULL == m_pScreen) return Video_Render_Err_CreatWindowFail; m_pOverlay = SDL_CreateYUVOverlay(m_nWindowWidth, m_nWindowHeight, SDL_YV12_OVERLAY, m_pScreen); if (EC_NULL == m_pOverlay) return Video_Render_Err_CreatRenderFail; SetVideoRect(&m_sSDLRect); return Video_Render_Err_None; }
bool KissWindow::create(const char* caTitle, int iWidth, int iHeight, int iBPP, bool bFullScreen, bool bResizeable) { // redirect console output back to console #ifdef DEBUG fopen("CON", "w"); freopen("CON", "w", stdout); freopen("CON", "w", stderr); #endif if (bCreated == true) { return false; } this->setType("KissWindow"); this->setName("frmWindow"); this->bRunning = false; this->bCanFocus = false; this->bPassEventsToParent = true; this->bFullScreen = bFullScreen; this->bResizeable = bResizeable; this->setBackgroundColor(CFG_APP_COLOR_BGN_RED, CFG_APP_COLOR_BGN_GREEN, CFG_APP_COLOR_BGN_BLUE); //- Events ----------------------------------------------- onLoadEvent = NULL; onUpdateEvent = NULL; //-------------------------------------------------------- if (SDL_Init(SDL_INIT_VIDEO) < 0) { cout << "SDL_Init - Error: " << SDL_GetError() << endl; exit(EXIT_FAILURE); } atexit(SDL_Quit); SDL_putenv("SDL_VIDEO_CENTERED=center"); this->setTitle(caTitle); this->setBPP(iBPP); this->setSize(iWidth, iHeight); this->bCreated = true; return this->bCreated; }
Manager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), gdata( Gamedata::getInstance() ), drawTheStupidHud(false), io( IOManager::getInstance() ), clock( ), screen( io->getScreen() ), clouds( SpriteFrameFactory::getInstance()->getFrame("back", "back"), 2 ), hills( SpriteFrameFactory::getInstance()->getFrame("hill", "hill"), 1 ), ghostbcknd(SpriteFrameFactory::getInstance()->getFrame("ghostbcknd", "ghostbcknd"), 1 ), view(Viewport::getInstance()), pter( NULL ), pterleft(NULL), var1(0), var2(0), gui(), remainingTime(60), orbs() { if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } Vector2f position(gdata->getXmlInt("pterX"), gdata->getXmlInt("pterY")); Vector2f velocity(gdata->getXmlInt("pterXspeed"), gdata->getXmlInt("pterYspeed")); pter = new MultiSprite(position, velocity, MultiSpriteFrameFactory::getInstance()->getFrame("pter","pter"), "pter"); pterleft= new MultiSprite(position, velocity, MultiSpriteFrameFactory::getInstance()->getFrame("pterleft","pterleft"), "pterleft"); orbs.pter = pter; orbs.pterLeft = pterleft; view->setObjectToTrack(pter); atexit(SDL_Quit); SDL_WM_SetCaption( "*** CpSc 870: Nikhil Bendre - Ghost Busters ***", NULL ); }