示例#1
0
  virtual void Draw()
  {
    // Don't draw name of local player ?
    if (IsVisible() && m_player->GetId() != GetLocalPlayerId())
    {
      //Assert(m_player->GetAABB());
      //DrawAABB(*(m_player->GetAABB()));
 
      // Print name 
      // TODO Do all these in one go, to minimise state changes
      AmjuGL::PushAttrib(AmjuGL::AMJU_BLEND | AmjuGL::AMJU_DEPTH_READ);
      AmjuGL::Enable(AmjuGL::AMJU_BLEND);
      AmjuGL::Disable(AmjuGL::AMJU_DEPTH_READ);

      GuiText text;
      text.SetTextSize(5.0f); // TODO CONFIG
      text.SetText(m_player->GetName());
    
      static const float MAX_NAME_WIDTH = 4.0f; // minimise this to reduce overdraw - calc from text
      text.SetSize(Vec2f(MAX_NAME_WIDTH, 1.0f));
      text.SetJust(GuiText::AMJU_JUST_CENTRE);
      //text.SetInverse(true);
      //text.SetDrawBg(true);
      text.SetFgCol(Colour(1, 1, 1, 1));

      AmjuGL::PushMatrix();
    
      Matrix m;
      m.SetIdentity();

      // Reverse modelview rotation
      Matrix r;
      r.ModelView();
      m = TransposeRot(r);

      Vec3f tr(m_combined[12], m_combined[13], m_combined[14]);
      m.TranslateKeepRotation(tr);
      AmjuGL::MultMatrix(m);
      static const float SCALE_FACTOR = 20.0f;
      float x = MAX_NAME_WIDTH * SCALE_FACTOR * -0.5f;
      AmjuGL::Translate(x, 60.0f, 0); // TODO CONFIG
    
      AmjuGL::Scale(SCALE_FACTOR, SCALE_FACTOR, 10);  

      text.Draw();
      AmjuGL::PopMatrix();
      AmjuGL::PopAttrib();
    }
  }
示例#2
0
void Game::RunOneLoop()
{
#ifdef SHOW_FRAME_TIME
    static std::string fps;
    static int framesThisSec = 0;
    framesThisSec++;
    static int elapsed = 0;
    float e = TheTimer::Instance()->GetElapsedTime(); 

    if ((int)e != elapsed)
    {
      elapsed = (int)e;
      fps = ToString(framesThisSec);
      framesThisSec = 0;
    }

#ifdef WIN32
    unsigned long start = GetTickCount();
#else
    // Get time taken to update/draw/flip, giving the 'real' FPS, not fixed to screen refresh rate
    timeval tbefore;
    gettimeofday(&tbefore, 0);
#endif

#endif //  SHOW_FRAME_TIME

  Update();

#ifdef SHOW_FRAME_TIME
#ifdef WIN32
    unsigned long mid = GetTickCount();
#else
    // Get time taken to update/draw/flip, giving the 'real' FPS, not fixed to screen refresh rate
    timeval mid;
    gettimeofday(&mid, 0);
#endif
#endif //  SHOW_FRAME_TIME

  Draw();

#ifdef SHOW_FRAME_TIME
  if (m_font)
  {
#ifdef WIN32
    unsigned long draw = GetTickCount() - mid;
    unsigned long update = mid - start;
    std::string s = "Draw: " + ToString((unsigned int)draw) + " update: " + ToString((unsigned int)update);

#else
    timeval tafter;
    gettimeofday(&tafter, 0);
    double draw = tafter.tv_sec - mid.tv_sec + (tafter.tv_usec - mid.tv_usec) * 1e-6;
    double update = mid.tv_sec - tbefore.tv_sec + (mid.tv_usec - tbefore.tv_usec) * 1e-6;
    int idraw = (int)(draw * 1000.0f);
    int iupdate = (int)(update * 1000.0f);
    std::string s = std::string("Draw: ") + 
      std::string((idraw < 10 ? "0" : "")) + ToString(idraw) +
      std::string("ms update: ") + std::string((iupdate < 10 ? "0" : "")) + 
      ToString(iupdate) + "ms";
#endif

    s += " fps: " + fps;

    // Display time per frame
    static GuiText t;
    t.SetFont(m_font);
    t.SetScaleX(0.7f);
    t.SetFgCol(Colour(1, 1, 1, 1));
    t.SetLocalPos(Vec2f(-1.0f, 1.0f));
    t.SetSize(Vec2f(2.0f, 0.1f));
    t.SetJust(GuiText::AMJU_JUST_LEFT);
    t.SetText(s);
    AmjuGL::PushAttrib(AmjuGL::AMJU_LIGHTING | AmjuGL::AMJU_TEXTURE_2D);
    AmjuGL::Disable(AmjuGL::AMJU_LIGHTING);
    AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D);
    t.Draw(); 
    AmjuGL::PopAttrib();
  }
#endif //  SHOW_FRAME_TIME

  AmjuGL::Flip(); 
}
示例#3
0
void Ve1NameNode::Draw()
{
  // Print name 
  // TODO Do all these in one go, to minimise state changes
  AmjuGL::PushAttrib(AmjuGL::AMJU_BLEND | AmjuGL::AMJU_DEPTH_READ);
  AmjuGL::Enable(AmjuGL::AMJU_BLEND);
  AmjuGL::Disable(AmjuGL::AMJU_DEPTH_READ);

  GuiText text;
  text.SetTextSize(5.0f); // TODO CONFIG
  text.SetText(ToString(*m_obj));
    
  static const float MAX_NAME_WIDTH = 4.0f; // minimise this to reduce overdraw - calc from text
  text.SetSize(Vec2f(MAX_NAME_WIDTH, 1.0f));
  text.SetJust(GuiText::AMJU_JUST_CENTRE);
  //text.SetInverse(true);
  //text.SetDrawBg(true);

  AmjuGL::PushMatrix();
    
  Matrix m;
  m.SetIdentity();
  //Vec3f tr(m_local[12], m_local[13], m_local[14]);
  Vec3f tr(m_combined[12], m_combined[13], m_combined[14]);
  m.Translate(tr);
  AmjuGL::MultMatrix(m);
  static const float SCALE_FACTOR = 20.0f;
  float x = MAX_NAME_WIDTH * SCALE_FACTOR * -0.5f;
  AmjuGL::Translate(x, 60.0f, 0); // TODO CONFIG
    
  AmjuGL::Scale(SCALE_FACTOR, SCALE_FACTOR, 10);  

  text.Draw();
  AmjuGL::PopMatrix();
  AmjuGL::PopAttrib();

  /*
  AmjuGL::PushAttrib(
    AmjuGL::AMJU_TEXTURE_2D | AmjuGL:: AMJU_LIGHTING | AmjuGL::AMJU_BLEND | AmjuGL::AMJU_DEPTH_READ | AmjuGL::AMJU_DEPTH_WRITE);

  AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D);
  AmjuGL::Disable(AmjuGL::AMJU_LIGHTING);
  AmjuGL::Enable(AmjuGL::AMJU_BLEND);
  AmjuGL::Disable(AmjuGL::AMJU_DEPTH_READ);
  AmjuGL::Disable(AmjuGL::AMJU_DEPTH_WRITE);

  AmjuGL::PushMatrix();
  AmjuGL::SetIdentity();

  AmjuGL::SetMatrixMode(AmjuGL::AMJU_PROJECTION_MATRIX);
  AmjuGL::PushMatrix();
  AmjuGL::SetIdentity();

  MultColour(Colour(0, 0, 1, 1));
  GuiText text;
  text.SetTextSize(0.5f);
  std::string s = "Object " + ToString(m_obj->GetId()) + " " + m_obj->GetTypeName();
  text.SetText(s);
  text.SizeToText();
  text.SetJust(GuiText::AMJU_JUST_LEFT);
  text.SetLocalPos(screenpos);
  text.Draw();


  AmjuGL::PopMatrix();
  AmjuGL::SetMatrixMode(AmjuGL::AMJU_MODELVIEW_MATRIX);
  AmjuGL::PopMatrix();

  AmjuGL::PopAttrib();
  */
}