/** * Class constructor, set window properties from Configuration object and init SDL and OpenGL widnow. * @param configuration is pointer to Configuration class. */ WindowManager::WindowManager() { windowCaption ="Kernel Panic"; initializeSDL(); Configuration* config = Configuration::getInstance(); _putenv(_strdup("SDL_VIDEO_CENTERED=1")); if (!config->getFullscreen()) windowScreen = SDL_SetVideoMode(config->getWidth(), config->getHeight(), config->getColorDepth(), SDL_OPENGL| SDL_DOUBLEBUF | SDL_HWSURFACE); else windowScreen = SDL_SetVideoMode(config->getWidth(), config->getHeight(), config->getColorDepth(), SDL_OPENGL | SDL_FULLSCREEN); if(!windowScreen) { printf("Video set mode failed: %s\n", SDL_GetError()); exit(0); } SDL_WM_SetCaption(windowCaption.c_str(), NULL); //SDL_WM_GrabInput(SDL_GRAB_ON); resizeOpenGL(config->getWidth(),config->getHeight()); initializeOpenGL(); }
RWindow::RWindow(const std::string & title = "") { m_window = nullptr; m_surface = nullptr; m_title = title; if(!initializeSDL()) { std::cerr << "Exiting.\n"; SDL_Quit(); std::exit(1); } glewExperimental = GL_TRUE; glewInit(); glViewport(0, 0, m_width, m_height); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Enable blending glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); quit = false; m_cursorType = CURSOR_ARROW; }
Engine::Engine(const std::string& title, int screenWidth, int screenHeight, bool screenFull) : m_titile(title) , m_screenWidth(screenWidth) , m_screenHeight(screenHeight) , m_screenFull(screenFull) , m_appActive(true) , m_mouseFocus(true) , m_inputFocus(true) , m_translate_x(0.0f) , m_translate_y(0.0f) , m_translate_z(0.0f) , m_scale(SCALE) , m_game(0) { try { initializeSDL(); initializeOpenGL(); SDL_WM_SetCaption(title.c_str(), title.c_str()); } catch (EngineError e) { SDL_Quit(); throw e; } // Mark all keys as not pressed for (int i = 0; i < SDLK_LAST; ++i) { m_keys[i] = false; } new ResourceMgr; // Required by GUI SDL_EnableUNICODE(1); new GuiMgr; }
SDLWindow::SDLWindow(Parameters& parameters) : AbstractWindow(parameters) { initializeSDL(); //initializeSDLimage(); //initializeSDLttf(); initializeOpenGL(); m_renderer->initialize(); // Called here after the context is created. }
graphicsLibrary::graphicsLibrary(){ initializeSDL(); loadScreen(); loadInitialTransMat(); rotatex(0); done = false; polyBegin = false; startTime = SDL_GetTicks(); frame = 0; }
int main(int argc, char* argv[]) { initializeSDL(); // Start Menu titleSurface = TTF_RenderText_Solid(silkscreen, "Simple Pong", white); titleTexture = SDL_CreateTextureFromSurface(renderer, titleSurface); titleRect.w = 512; titleRect.h = 128; titleRect.x = SCREEN_WIDTH / 2 - titleRect.w / 2; titleRect.y = 25; // Start Button startButtonSurface = TTF_RenderText_Solid(silkscreen, "Start", white); startButtonTexture = SDL_CreateTextureFromSurface(renderer, startButtonSurface); startButtonRect.w = 128; startButtonRect.h = 48; startButtonRect.x = SCREEN_WIDTH / 2 - startButtonRect.w / 2; startButtonRect.y = SCREEN_HEIGHT / 2; defineRects(); while(!quit) // Main Loop { while(SDL_PollEvent(&e) != 0) { if(e.type == SDL_QUIT) quit = 1; } getKeystates(); switch(screen) { case 0: // Start Menu clearScreen(); renderStartMenu(); break; case 1: // Game ballPhysics(); clearScreen(); renderGame(); break; case 2: // Pause Menu clearScreen(); SDL_RenderCopy(renderer, startMessageTexture, NULL, &startMessageRect); renderGame(); break; } SDL_Delay(2); // Slow down the loop. } quitSDL(); // Quit all SDL subsystems and free memory. return 0; }
// Initialization functions bool osgSDLViewer::init(void) { if ( !initializeSDL() ) return false; //if ( !initializeTimer() ) //return false; if ( !initializeSceneMgr() ) return false; return true; }
int startGame() { Timer fpsTimer; if (initializeSDL() == -1) { exit(-1); } else { //Create window if (GameEngine::getInstance().init() == Mario::STATUS_FATAL) { exit(Mario::STATUS_FATAL); } else { while( GameEngine::getInstance().getStateId() != STATE_EXIT ) { fpsTimer.start(); GameState* state = GameEngine::getInstance().getState(); state->handle_events(); state->logic(); state->render(); GameEngine::getInstance().changeState(); refreshScreen(); if (fpsTimer.getTicks() < Mario::UPDATE_RATE ) { SDL_Delay ( Mario::UPDATE_RATE - fpsTimer.getTicks() ); } } } } GameEngine::getInstance().shutdown(); //Quit SDL subsystems IMG_Quit(); SDL_Quit(); return 0; }
int main(int argc, char* args[]) { int iResult; iResult = connection.initConnection(); if (iResult != 0) { printf("Failed to initialize server connection!\n"); //Wait for 4s SDL_Delay(4000); } if (!initializeSDL()) { printf("Failed to initialize! Exiting program.\n"); //Wait for 4s SDL_Delay(4000); } else { window = createWindow("NettiiSaatana", 800, 600); renderer = createRenderer(window); if (window == nullptr || renderer == nullptr) { printf("Failed to create graphics context! Exiting program.\n"); //Wait for 4s SDL_Delay(4000); } else { //Program running bool bool quitProgram = false; //Event handler SDL_Event sdlEvent; uint8_t* keyState = (uint8_t*)SDL_GetKeyboardState(NULL); KEYS_INFO keysInfo; //uint8_t* mouseButtonState = (uint8_t*)SDL_GetMouseState(NULL); int mouseX = 0, mouseY = 0; bool leftClick = false, bulletSpwnd = false; float difX, difY, magnitude; const float PI = 3.14159265; float velocityX, velocityY; SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); playerTex->loadImage(renderer, "groundtx.png"); addPlayer(0); bulletTex->loadImage(renderer, "bullet.png"); initBulletList(100); std::thread commThread(handleComms); commThread.detach(); while (!quitProgram) { if (players.size() > playerNumber) { while (SDL_PollEvent(&sdlEvent) != 0) { if (sdlEvent.type == SDL_QUIT) quitProgram = true; if (sdlEvent.type == SDL_KEYDOWN || sdlEvent.type == SDL_KEYUP) keyState = (uint8_t*)SDL_GetKeyboardState(NULL); if (sdlEvent.type == SDL_MOUSEMOTION) SDL_GetMouseState(&mouseX, &mouseY); if (sdlEvent.type == SDL_MOUSEBUTTONDOWN) { if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) leftClick = true; } if (sdlEvent.type == SDL_MOUSEBUTTONUP) { if (!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))) leftClick = false; bulletSpwnd = false; } } keysInfo.w = 0; keysInfo.a = 0; keysInfo.s = 0; keysInfo.d = 0; if (keyState[SDL_SCANCODE_ESCAPE]) quitProgram = true; if (keyState[SDL_SCANCODE_W]) keysInfo.w = 1; if (keyState[SDL_SCANCODE_A]) keysInfo.a = 1; if (keyState[SDL_SCANCODE_S]) keysInfo.s = 1; if (keyState[SDL_SCANCODE_D]) keysInfo.d = 1; float angle = std::atan2(((double)mouseY - (players[playerNumber]->getPosition().y + players[playerNumber]->getOrigin().y)), ((double)mouseX - (players[playerNumber]->getPosition().x + players[playerNumber]->getOrigin().x))); angle *= (180 / PI); if (angle < 0) { angle += 360; } else if (angle > 360) { angle -= 360; } iResult = connection.sendKeyStates(keysInfo, angle); if (iResult != 0) { printf("Failed to send key states to server!\n"); } if (leftClick == true && bulletSpwnd == false) { bulletSpwnd = true; iResult = connection.sendShootCmd(); if (iResult != 0) { printf("Failed to send shoot command to server!\n"); } } //Clear screen SDL_RenderClear(renderer); //Render players to screen for (std::map<int, Sprite*>::iterator it = players.begin(); it != players.end(); it++) { (*it).second->draw(renderer); } //Render bullets to screen for (std::map<int, Bullet*>::iterator it = bullets.begin(); it != bullets.end(); it++) { if ((*it).second->isOn()) { (*it).second->draw(renderer); } } //Update screen SDL_RenderPresent(renderer); } } } } //Destroy window SDL_DestroyWindow(window); //Quit SDL subsystems SDL_Quit(); return 0; }
void videoplayer::loadFile(){ emit first_play(); /* genero un nuovo oggetto VideoState */ is = VideoState(); /*inizializzo la finestra */ window = new Video(); /* alla chiusura della finestra mando in stop */ connect(window, &Video::windowClosing, this, &videoplayer::stop); /* collego il bottone stop alla rispettiva SLOT */ connect(stopAction, &QAction::triggered, this, &videoplayer::quit); /* evento di chiusura della finestra da X finestra */ connect(window, &Video::Xpressed, this, &videoplayer::quit); //ogni volta che dal clock viene richiesto un update della finestra, richiamo lo slot updateGL connect(_clock, &AVClock::needupdate, window, &Video::updateGL); _clock->reset(); //resetto il clock _clock->SetVideoState(&is); //gli passo il puntatore a VideoState is.setSourceFilename(this->getSourceFilename()); //imposto il nome del file all'oggetto VideoState is.window = window; window->show(); // Register all formats and codecs av_register_all(); //inizializzazione di SDL audio interface if(initializeSDL() == -1){ exit(1); } /* mando in esecuzione il primo refresh, gli altri avverranno in cascata, grazie alla connect */ _clock->schedule_refresh(40); /* inizializzazione finestra istogramma */ histo_window = new HistoDraw(); is.histo_window = histo_window; connect(_clock, &AVClock::needupdate, histo_window, &HistoDraw::updateGL); /* inizializzazione thread istogramma */ _histo = new HistoThread(); _histo->SetVideoState(&is); _histo->start(); /* lancio il thread di decodifica generale, apre i rispettivi codec, legge stream x stream e genera paccehtti audio e video che eseguiranno i distinti thread */ _demuxer = new DecodeThread(); //inizializzo oggetto DecodeThread _demuxer->SetVideoState(&is); _demuxer->SetAVClock(_clock); _demuxer->set(_demuxer); //setto puntatore statico all'oggetto is.parse_tid = _demuxer; connect(_demuxer, &DecodeThread::eof, window, &Video::closeWindow); connect(_demuxer, &DecodeThread::eof, histo_window, &HistoDraw::closeWindow); _demuxer->start(); /** connect per l'aggiornamento del max valore possibile dello slider coincidente con la durata del video in secondi */ connect(_demuxer, &DecodeThread::setSliderRange, positionSlider, &QSlider::setRange); //nota: VideoState di default dovrebbe avere un riferimento al thread.... if(!is.parse_tid) { //qDebug() << "ERRORE: riferimento al thread di decompressione mancante"; exit(1); } return; }