MinVR  0.9.0
A multi-platform virtual reality library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WindowGLFW.H
Go to the documentation of this file.
1 //========================================================================
2 // MinVR - AppKit GLFW
3 // Platform: Any
4 // API version: 1.0
5 //------------------------------------------------------------------------
6 // The MIT License (MIT)
7 //
8 // Copyright (c) 2013 Regents of the University of Minnesota
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy of
11 // this software and associated documentation files (the "Software"), to deal in
12 // the Software without restriction, including without limitation the rights to
13 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14 // the Software, and to permit persons to whom the Software is furnished to do so,
15 // subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included in all
18 // copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //========================================================================
27 
28 #ifndef WINDOWGLFW_H
29 #define WINDOWGLFW_H
30 
31 
32 #include "GL/glew.h"
33 #ifdef _WIN32
34 #include "GL/wglew.h"
35 #else
36 #include "GL/glxew.h"
37 #endif
38 
39 #include <GLFW/glfw3.h>
40 
41 #include "MVRCore/AbstractWindow.H"
42 #include "MVRCore/Event.H"
43 #include <map>
44 #include <boost/algorithm/string.hpp>
45 #include <string>
46 #include <glm/glm.hpp>
47 
48 namespace MinVR {
49 
50 class WindowGLFW : public AbstractWindow
51 {
52 public:
53  WindowGLFW(WindowSettingsRef settings, std::vector<AbstractCameraRef> cameras);
54  ~WindowGLFW();
55 
56  void pollForInput(std::vector<EventRef> &events);
57  void swapBuffers();
58  void makeContextCurrent();
59  void releaseContext();
60  int getWidth();
61  int getHeight();
62  int getXPos();
63  int getYPos();
64  GLFWwindow* getWindowPtr();
65 
69  void setSize(int width, int height, bool actuallySet);
70 
74  void setPosition(int xPos, int yPos, bool actuallySet);
75 
79  void appendEvent(EventRef newEvent);
80 
84  void setCursorPosition(double x, double y);
85 
88  glm::vec2 getCursorPosition();
89 
95  static std::map<GLFWwindow*, WindowGLFW*> pointerToObjectMap;
96  static std::map<GLFWwindow*, WindowGLFW*> initPointerToObjectMap();
97 
98  static void window_size_callback(GLFWwindow* window, int width, int height);
99  static void window_pos_callback(GLFWwindow* window, int xpos, int ypos);
100  static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
101  static void cursor_position_callback(GLFWwindow* window, double x, double y);
102  static void cursor_enter_callback(GLFWwindow* window, int entered);
103  static void scroll_callback(GLFWwindow* window, double x, double y);
104  static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
105 
106 private:
107  GLFWwindow* _window;
108  int _width;
109  int _height;
110  int _xPos;
111  int _yPos;
112  std::vector<EventRef> _currentEvents;
113  glm::vec2 _cursorPosition;
114 
115  void initGLEW();
116 
117  // Keypress helper methods
118  static std::string getKeyName(int key);
119  static std::string getKeyValue(int key, int mods);
120  static std::string getActionName(int action);
121  static std::string getButtonName(int button);
122  static std::string getModsName(int mods);
123 
124  void initDebugCallback();
125  bool firstTime;
126 
127  static void formatDebugOutputARB(char outStr[], size_t outStrSize, GLenum source, GLenum type, GLuint id, GLenum severity, const char *msg);
128  static void formatDebugOutputAMD(char outStr[], size_t outStrSize, GLenum category, GLuint id, GLenum severity, const char *msg);
129  static void CALLBACK debugCallbackARB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam);
130  static void CALLBACK debugCallbackAMD(GLuint id, GLenum category, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam);
131 };
132 
133 } // end namespace
134 
135 #endif