Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ContextGLUT.hh
1 #ifndef __CONTEXT_GLUT_HH__
2 #define __CONTEXT_GLUT_HH__
3 
4 #include <bias_config.h>
5 #ifndef BIAS_HAVE_GLUT
6 # error You need glut. Please recompile BIAS with USE_GLUT.
7 #endif //BIAS_HAVE_GLUT
8 
9 #include "RenderContextBase.hh"
10 #include <vector>
11 
12 //activate to have fps output on window title
13 //#define GLUT_TIME_MEASURE
14 
15 namespace BIAS {
16 
17  // forward declaration of function (for gcc-4.2)
18  void MouseMotionFunc_(int x, int y);
19  void MousePassiveMotionFunc_(int x, int y);
20  void MouseButtonFunc_(int button, int state, int x, int y);
21  void SpecialKeyFunc_(int key, int x, int y);
22  void SpecialKeyUpFunc_(int key, int x, int y);
23  void StandardKeyFunc_(unsigned char key, int x, int y);
24  void StandardKeyUpFunc_(unsigned char key, int x, int y);
25  void Reshape_(int width, int height);
26  void Render_();
27  void WhenIdle_();
28 
29  /** \class ContextGLUT
30  \brief Wrapper to glut-library.
31  Automatisation and unififcation of callback registration following
32  the model implemented in class hierarchy.
33  Does not create windows nor start the main loop. The application still
34  needs to do it herself.
35  \author bartczak
36  \ingroup g_glviewer
37  */
38  class BIASGLviewer_EXPORT ContextGLUT : public RenderContextBase
39  {
40  public:
41 
42  void SetDoubleClickInterval(unsigned int ms) {doubleClickInterval_ = ms;}
43 
44  virtual void Redisplay();
45 
46  ContextGLUT(int x0 = 0, int y0 = 0,
47  int width = 400, int height = 600,
48  const std::string& name = "ContextGLUT Window",
49  const char* initDisplayString = NULL,
50  int* commandLineArgc = NULL,
51  char** commandLineArgv = NULL);
52 
53  ContextGLUT(std::string gamemodestring,
54  const std::string& name = "ContextGLUT Window",
55  const char* initDisplayString = NULL,
56  int* commandLineArgc = NULL,
57  char** commandLineArgv = NULL);
58 
59  virtual ~ContextGLUT();
60 
61  virtual void MakeGLContextCurrent();
62 
63  virtual void SetTimer(unsigned int interval);
64  virtual void DeactivateTimer();
65 
66  int GetGlutWindowID() {return windowID_;}
67 
68 #ifdef GLUT_TIME_MEASURE
69  static std::vector<double> fpsMeasures;
70  static unsigned int measurementsCount_;
71 #endif
72 
73 
74  protected:
75  /** Initialization of glut library, initial display state and registration
76  * of callbacks.
77  * Same as calling glutInit(commandLineArgc, commandLineArgv) and
78  * glutInitDisplayString(initDisplayString). Must be called before
79  * CreateWindow() and glutMainLoop().
80  * @{
81  */
82  virtual void InitContext_(const char* initDisplayString = NULL,
83  int* commandLineArgc = NULL,
84  char** commandLineArgv = NULL);
85 
86  /**
87  * @}
88  */
89 
90  /** Creates a glut window and registers all known callbacks to it.
91  */
92  virtual void CreateWindow_(int x0, int y0, int width, int height,
93  const std::string& name);
94 
95  virtual void DestroyWindow_();
96 
97  friend void MouseMotionFunc_(int x, int y);
98  friend void MousePassiveMotionFunc_(int x, int y);
99  friend void MouseButtonFunc_(int button, int state, int x, int y);
100  friend void SpecialKeyFunc_(int key, int x, int y);
101  friend void StandardKeyFunc_(unsigned char key, int x, int y);
102  friend void SpecialKeyUpFunc_(int key, int x, int y);
103  friend void StandardKeyUpFunc_(unsigned char key, int x, int y);
104  friend void Reshape_(int width, int height);
105  friend void Render_();
106  friend void WhenIdle_();
107 
108  void RegisterCallbacks_() const;
109 
110 
111  unsigned int doubleClickInterval_;
112 
114  std::vector<ContextGLUT*>::iterator registrationIterator_;
115 
116  void EnterGameMode_(const std::string gamemodestring);
117  bool gameMode_;
118  };
119 }
120 
121 #endif
void WhenIdle_()
unsigned int doubleClickInterval_
Definition: ContextGLUT.hh:111
void Reshape_(int width, int height)
void SpecialKeyFunc_(int key, int x, int y)
void Render_()
Wrapper to glut-library.
Definition: ContextGLUT.hh:38
void StandardKeyFunc_(unsigned char key, int x, int y)
void SetDoubleClickInterval(unsigned int ms)
Definition: ContextGLUT.hh:42
void SpecialKeyUpFunc_(int key, int x, int y)
void MouseButtonFunc_(int button, int state, int x, int y)
void StandardKeyUpFunc_(unsigned char key, int x, int y)
std::vector< ContextGLUT * >::iterator registrationIterator_
Definition: ContextGLUT.hh:114
void MouseMotionFunc_(int x, int y)
Definition: ContextGLUT.cpp:60
void MousePassiveMotionFunc_(int x, int y)
Base for all classes creating interface between GL and &quot;window manager&quot;.