Пример #1
0
void video::saveImage(sf::Window &app, int framerate)
{
  if (!app.isOpen())
    return ;
  sf::Vector2u size = app.getSize();
  if (videoTexture.getSize().y != size.y)
    videoTexture.create(size.x, size.y);

  if (videoTimer.getElapsedTime().asMilliseconds() > 1000/framerate)
    {
      videoTimer.restart();

      std::ostringstream videoFramePath;

      videoFramePath << "/tmp/gl-engine-"
		     << std::setw(5)
		     << std::setfill('0')
		     << currentVideoFrame
		     << ".jpg";
      videoTexture.update(app);
      sf::Image videoImage = videoTexture.copyToImage();
      videoImage.saveToFile(videoFramePath.str());
      currentVideoFrame++;
    }
}
Пример #2
0
int main()
{
	init();

	while (window.isOpen())
	{
		step();
		pollEvents();
	}

	cleanUp();

	return 0;
}
Пример #3
0
int main (int argc, char **argv)
{
	//Init with start Position
    xpos=9;
    ypos=9;
    zpos=15;
    xrot=50; //80°
    yrot=135; //135°

    // Set the color and depth clear values
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Enable Z-buffer read and writeca
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    perspectiveGL(40.f, (1.f * xres / yres), 1.f, 500.f);
	LoadTextures();

	while (DSWindow.isOpen()) // Game loop
	{		
		//calculate Time
		maintimer.stop();
		difTime = maintimer.getElapsedTimeInSec();
        if (difTime > 0.1) difTime = 0;	//remove first time
		gesTime += difTime;
		maintimer.start();
		


     	//Clear Screen and set OpenGL Settings
		DSWindow.setActive();
     	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     	glMatrixMode(GL_MODELVIEW);
     	glLoadIdentity();
 		glClearColor (0.0,0.0,0.0,1.0); //clear the screen to black
 		enableGlOptions();	//enable graphic-settings

        inputmanager(difTime);	//mve camera etc

        world();		//draw the "World

//        levelDrawer1.drawAntMap(0);
        levelDrawer1.drawBlocks();


        if(gameStart)
        {
            antHill1.ki();
            antHill1.antanimation();
        }

        DrawHUD();		//draw the HUD

     	// Finally, display the rendered frame on screen
     	DSWindow.display();
	}
return EXIT_SUCCESS;
}
    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();
        }
    }