//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  This file contains the declaration of the CGLUTShaderContext        //
//  class.                                                              //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
#ifndef __CGLUTSHADERCONTEXT_HPP__
#define __CGLUTSHADERCONTEXT_HPP__


#include <memory>
#include "real.hpp"
#include "CCamera.hpp"

class CScene;
class CShaderProgram;


//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  This class is a singleton that sets up a OpenGL context and handle  //
//  GLUT-specific events.                                               //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
class CGLUTShaderContext
{
public:
  static CGLUTShaderContext* getInstance();
  bool init(int *argc, char** argv,
            const CScene& scene, const std::string& shaderCode);
  void show();

private:
  CGLUTShaderContext();
  CGLUTShaderContext(const CGLUTShaderContext&); // Not defined, should never be called
  ~CGLUTShaderContext();

  real_t                        m_aspectRatio;
  real_t                        m_angle;
  CCamera                       m_camera;
  std::auto_ptr<CShaderProgram> m_pShaderProgram;

  // GLUT callbacks
  static void displayFunc(void);
  static void reshapeFunc(int width, int height);
  static void keyboardFunc(unsigned char key, int x, int y);
  static void specialFunc(int key, int x, int y);
  static void mouseFunc(int button, int state, int x, int y);
  static void motionFunc(int x, int y);
  static void moveIdleFunc();

  enum BUTTON_ID { BUTTON_NONE   = 0x0,
                   BUTTON_LEFT   = 0x1,
                   BUTTON_MIDDLE = 0x2,
                   BUTTON_RIGHT  = 0x4 };

  int m_buttonState;
  int m_lastFrameTime;
  int m_lastPosX;
  int m_lastPosY;
};


#endif // __CGLUTSHADERCONTEXT_HPP__
