Esempio n. 1
0
void init()
{
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);

  auto error_ = glewInit();
  std::cout << error_ << std::endl;

  counter.start();

  /* check the OpenGL version */
  char *buff = (char*)glGetString(GL_VERSION);
  std::cout << buff << std::endl;

  /* check the vendor and the graphics card */
  buff = (char*)glGetString(GL_VENDOR);
  std::cout << buff << std::endl;
  buff = (char*)glGetString(GL_RENDERER);
  std::cout << buff;

  gm.reset(new GameManager());
  gm->init();

  for(int i=0; i<30; i++)
    keyPressed[i]=false;
}
Esempio n. 2
0
void display()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  gm->update(counter.fps());
  gm->render();

//  if(keyPressed[KEY_ID_W]==true)      gm->getCam()->moveForward();
//  if(keyPressed[KEY_ID_A]==true)      gm->getCam()->moveLeft();
//  if(keyPressed[KEY_ID_D]==true)      gm->getCam()->moveRight();
//  if(keyPressed[KEY_ID_S]==true)      gm->getCam()->moveBackward();
//  if(keyPressed[KEY_ID_SPACE]==true)  gm->getCam()->moveUp();
//  if(keyPressed[KEY_ID_C]==true)      gm->getCam()->moveDown();



  if(keyPressed[KEY_ID_RIGHT]==true)  gm->getShip()->moveRight();
  if(keyPressed[KEY_ID_LEFT]==true)   gm->getShip()->moveLeft();
  if(keyPressed[KEY_ID_UP]==true)     gm->getShip()->moveUp();
  if(keyPressed[KEY_ID_DOWN]==true)   gm->getShip()->moveDown();
  if((keyPressed[KEY_ID_SPACE]==true) && (gm->getShip()->getLife() > 0))
                      {
                                        gm->addBulletPlayer();
                                        keyPressed[KEY_ID_SPACE] = false;
                                        }
  int scores = gm->getShip()->getScores();
  std::ostringstream convert;
  convert << scores;
  std::string score;
  score = convert.str();
  ad->drawText(score.data(), score.size(),100,680);
  if (gm->getShip()->getLife() == 0){
    std::string gameover;
    std::ostringstream convert2;
    convert2 << gm->getShip()->getScores();
    std::string score2;
    score2 = convert2.str();
    gameover = "Game Over. Your score is: " + convert2.str();
    ad->drawText(gameover.data(), gameover.size(),250,400);
  }
  glutSwapBuffers();
  glutPostRedisplay();
}
Esempio n. 3
0
void init()
{
    GLenum err = glewInit();
    if (GLEW_OK != err) std::cout<<"Error: "<< glewGetErrorString(err);
    std::cout<<"Status: Using GLEW "<< glewGetString(GLEW_VERSION);

  glClearColor(0.3, 0.3, 0.3, 0.0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);

  counter.start();

  gm.reset(new GameManager());
  gm->init();


  for(int i=0; i<30; i++)
    keyPressed[i]=false;

  glEnable(GL_NORMALIZE);
}