MachineIntelligenceCore:Visualization
Window.cpp
Go to the documentation of this file.
1 
25 
26 namespace mic {
27 namespace opengl {
28 namespace visualization {
29 
30 Window::Window(std::string name_, unsigned int position_x_, unsigned int position_y_, unsigned int width_, unsigned int height_) :
31  name(name_), position_x(position_x_), position_y(position_y_), width(width_), height(height_)
32 {
33  // Initialize window and display modes.
34  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
35  glutInitWindowSize(width, height);
36  glutInitWindowPosition(position_x, position_y);
37 
38  // Create window.
39  id = glutCreateWindow(name.c_str());
40 
41  // Note: glutSetOption is only available with freeglut
42  // glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
43 
44  // Register main handlers.
45  glutDisplayFunc(VGL_MANAGER->displayHandler);
46  glutReshapeFunc(VGL_MANAGER->reshapeHandler);
47  glutKeyboardFunc(VGL_MANAGER->keyboardHandler);
48  glutMouseFunc(VGL_MANAGER->mouseHandler);
49 
50  // Set OpenGl antialiasing parameters.
51  glEnable(GL_LINE_SMOOTH);
52  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
53  glEnable(GL_POINT_SMOOTH);
54  glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
55  glEnable(GL_BLEND);
56  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
57 #ifndef _WIN32 // glBlendColor NOT SUPPORTED on windows GLUT
58  glBlendColor(1.0f, 1.0f, 1.0f, 0.6f);
59  glDisable(GL_MULTISAMPLE);
60 #endif
61 
62  // Set fullscreen mode to off.
63  fullscreen_mode = false;
64 
65  // Register default key handlers.
66  REGISTER_KEY_HANDLER('f', "f - toggles fullscreen on/off", &Window::keyhandlerFullscreen);
67 
68  // Register window!
69  VGL_MANAGER->registerWindow(this);
70 }
71 
73  // TODO Auto-generated destructor stub
74 }
75 
76 
77 unsigned int Window::getId() const {
78  return id;
79 }
80 
81 std::string Window::getName() const {
82  return name;
83 }
84 
85 void Window::reshapeHandler(int width_, int height_){
86 // printf("Window::reshapeHandler handler of %d window!\n", glutGetWindow());
87 
88  // Remember new width and height.
89  height = height_;
90  width = width_;
91 
92  // Change window size.
93  glViewport(0, 0, width, height);
94  glMatrixMode(GL_PROJECTION);
95  glLoadIdentity();
96 
97  // Set the coordinate system, with the origin in the top left.
98  gluOrtho2D(0, width, height, 0);
99  glMatrixMode(GL_MODELVIEW);
100 }
101 
102 
104  // Enter critical section.
105  APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
106 
107  if (!fullscreen_mode) {
108  // Remember window size.
111  // Read current window position.
112  position_x = glutGet((GLenum)GLUT_WINDOW_X);
113  position_y = glutGet((GLenum)GLUT_WINDOW_Y);
114  // Enter full screen.
115  glutFullScreen();
116  } else if (fullscreen_mode){
117  // Restore previous window size.
120  // Resize window.
121  glutReshapeWindow(width, height);
122  // Place it in the previous position.
123  glutPositionWindow(position_x, position_y);
124  }//: if
126 
127  // End of critical section.
128 }
129 
130 
131 } /* namespace visualization */
132 } /* namespace opengl */
133 } /* namespace mic */
Window(std::string name_="OpenGlWindow", unsigned int position_x_=0, unsigned int position_y_=0, unsigned int width_=512, unsigned int height_=512)
Definition: Window.cpp:30
unsigned int getId() const
Definition: Window.cpp:77
#define VGL_MANAGER
Macro returning OpenGL window manager instance.
Contains declaration of parent class of all OpenGL-based windows.
std::string getName() const
Definition: Window.cpp:81
virtual void reshapeHandler(int width_, int height_)
Definition: Window.cpp:85
Declaration of WindowManager class along with a bunch of helpful types and macros.