// Message class
// celes@tecgraf.puc-rio.br
// Jul 2002

#include "message.h"

#include <stdio.h>
#include <stdarg.h>
#include <assert.h>

void UtlMessage::SetColor (float red, float green, float blue)
{
  m_red = (uchar)(red*255);
  m_green = (uchar)(green*255);
  m_blue = (uchar)(blue*255);
}

void UtlMessage::SetFont (void* font)
{
  m_font = font;
}

void UtlMessage::SetPosition (float x, float y)
{
  m_x = x; m_y = y;
}

void UtlMessage::Display (const char* format, ...)
{
  static char msg[1024];
  va_list ap;
  msg[1023] = 1;
  va_start (ap, format);
  vsprintf (msg, format, ap);
  assert(msg[1023]==1);
  show(msg);
}

void UtlMessage::show (const char* text)
{
  glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
  glColor3ub(m_red,m_green,m_blue);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  glRasterPos3f(m_x,m_y,0.9F);

  int i;
  for (i=0; text[i]; ++i)
    glutBitmapCharacter(m_font,text[i]);

  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();
  glPopAttrib();
}
