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(); } }
void draw() { //Activate the window's context window.setActive(); //Various settings glClearColor(0.5, 0.5, 0.5, 0.0f); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_TEXTURE_2D); //Lighting GLfloat light_color[] = {0.9, 0.9, 0.9, 1.f}; glMaterialfv(GL_FRONT, GL_DIFFUSE, light_color); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); //Setup projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat ratio = float(window.getSize().x) / window.getSize().y; glFrustum(-ratio, ratio, -1.0, 1.0, 1.0, 500.0); //Store start time std::chrono::time_point<std::chrono::system_clock> startTime=std::chrono::system_clock::now(); //The rendering loop glMatrixMode(GL_MODELVIEW); while (window.isOpen()) { 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(); glTranslatef(0.0f, -20.0f, -45.0f); 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(); } }