void start() {
        std::chrono::time_point<std::chrono::system_clock> startTime=std::chrono::system_clock::now();

        //Event thread (main thread)
        bool running = true;
        while (running) {
            sf::Event event;
            while (window.pollEvent(event)) {
                if (event.type == sf::Event::KeyPressed) {
                    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
                        window.close();
                        running=false;
                    }
                }
                else if (event.type == sf::Event::Closed) {
                    window.close();
                    running = false;
                }
            }
            
            std::chrono::duration<double> elapsed_seconds = std::chrono::system_clock::now() - startTime;
            double time=elapsed_seconds.count();
            
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
        
            gluLookAt(0.0, 30.0, -65.0, //Camera position in World Space
                      0.0, 5.0, 0.0,    //Camera looks towards this position
                      0.0, 1.0, 0.0);   //Up
        
            glPushMatrix();
            glRotatef(-time*50.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            unanimatedAstroBoy.draw();
            glPopMatrix();
            
            glPushMatrix();
            glRotatef(-time*50.0+90.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            astroBoy.drawFrame(time);
            glPopMatrix();
            
            glPushMatrix();
            glRotatef(-time*50.0+180.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            astroBoyMovingGlasses.drawFrame(time);
            glPopMatrix();
            
            glRotatef(-time*50.0+270.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            astroBoyHeadBanging.drawFrame(time);
            
            //Swap buffer (show result)
            window.display();
        }
    }
Esempio n. 2
0
void mainEventHandler(sf::Window &window){

        sf::Event event;
        while (window.pollEvent(event))
        {
            switch (event.type){
                case sf::Event::Closed:
                    window.close();
                    break;

                case sf::Event::KeyPressed:
                    keyPressedHandler(event);
                    break;

                case sf::Event::KeyReleased:
                    keyReleasedHandler(event);
                    break;

                case sf::Event::LostFocus:
                    /* pause(); */
                    break;

                case sf::Event::GainedFocus:
                    /* resume(); */
                    break;


                default: break;
            }
        }
        
}
Esempio n. 3
0
void
windowEvents ( sf::Window& window)
{
    sf::Event e;

    while ( window.pollEvent ( e ) ) {
        if ( e.type == sf::Event::Closed ) {
            window.close();
        }
    }
}
void pollEvents()
{
	sf::Event windowEvent;
	while (window.pollEvent(windowEvent))
	{
		switch (windowEvent.type)
		{
		case sf::Event::Closed:
			window.close();
			break;
		}
	}
}
Esempio n. 5
0
	void renderLoop(sf::Window & window)
	{
		sf::Clock time;
		WorldState state;
		
		while (state.isRunning())
		{
			this->handleEvents(window, state);
			state.timeStep( time.getElapsedTime().asSeconds() );
			engine.display(state);
			window.display();
		}
		window.close();
	}
Esempio n. 6
0
	void InputHandler::processEvents(sf::Window& window) {
		reset();

		sf::Event event;
		while (window.pollEvent(event)) {
			switch (event.type) {
				case sf::Event::KeyPressed:
					if (key_press_callback_func != nullptr)
						key_press_callback_func(event.key);
					break;
				case sf::Event::KeyReleased:
					if (key_release_callback_func != nullptr)
						key_release_callback_func(event.key);
					break;
				case sf::Event::MouseMoved:
					m_NewMousePosition.x = event.mouseMove.x;
					m_NewMousePosition.y = event.mouseMove.y;

					if (mouse_moved_callback_func != nullptr)
						mouse_moved_callback_func(event.mouseMove);

					m_LastMousePosition.x = event.mouseMove.x;
					m_LastMousePosition.y = event.mouseMove.y;
					break;
				case sf::Event::MouseWheelScrolled:
					if (mouse_wheel_scroll_callback_func != nullptr)
						mouse_wheel_scroll_callback_func(event.mouseWheelScroll);
					break;
				case sf::Event::MouseButtonPressed:
					if (mouse_button_pressed_callback_func != nullptr)
						mouse_button_pressed_callback_func(event.mouseButton);
					StartDrag(event.mouseButton);
					break;
				case sf::Event::MouseButtonReleased:
					StopDrag(event.mouseButton);
					if (mouse_button_released_callback_func != nullptr)
						mouse_button_released_callback_func(event.mouseButton);
					break;
				case sf::Event::Closed:
					window.close();
					break;
			}
		}
	}
Esempio n. 7
0
	~Global() {
		wnd.close();
		delete e;
	}