8 cerr <<
"ERROR: (GLFW) " << desc << endl;
15 set<string> extensions;
17 glGetIntegerv(GL_NUM_EXTENSIONS, &nExtensions);
18 for (
int i = 0; i < nExtensions; i++)
19 extensions.insert(reinterpret_cast<char const *>(glGetStringi(GL_EXTENSIONS, i)));
23 cout <<
"OpenGL Caps:" << endl;
24 cout <<
" GL Version: " << glGetString(GL_VERSION) << endl;
25 cout <<
" Vendor: " << glGetString(GL_VENDOR) << endl;
26 cout <<
" Renderer: " << glGetString(GL_RENDERER) << endl;
27 cout <<
" GLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;
28 cout <<
" Extensions:" << endl;
29 for (
auto& extension : extensions)
30 cout <<
" " << extension << endl;
35 void APIENTRY
debugCallback(GLenum source, GLenum type, GLuint
id, GLenum severity, GLsizei length,
const GLchar* message, GLvoid* userParam)
40 if(source == GL_DEBUG_SOURCE_API_ARB) ss <<
"OpenGL";
41 else if(source == GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB) ss <<
"Windows";
42 else if(source == GL_DEBUG_SOURCE_SHADER_COMPILER_ARB) ss <<
"Shader Compiler";
43 else if(source == GL_DEBUG_SOURCE_THIRD_PARTY_ARB) ss <<
"Third Party";
44 else if(source == GL_DEBUG_SOURCE_APPLICATION_ARB) ss <<
"Application";
45 else if(source == GL_DEBUG_SOURCE_OTHER_ARB) ss <<
"Other";
47 string sourceStr = ss.str();
51 if(source == GL_DEBUG_TYPE_ERROR_ARB) ss <<
"Error";
52 else if(source == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB) ss <<
"Deprecated behavior";
53 else if(source == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB) ss <<
"Undefined behavior";
54 else if(source == GL_DEBUG_TYPE_PORTABILITY_ARB) ss <<
"Portability";
55 else if(source == GL_DEBUG_TYPE_PERFORMANCE_ARB) ss <<
"Performance";
56 else if(source == GL_DEBUG_TYPE_OTHER_ARB) ss <<
"Other";
58 string typeStr = ss.str();
62 if(source == GL_DEBUG_SEVERITY_HIGH_ARB) ss <<
"High";
63 else if(source == GL_DEBUG_SEVERITY_MEDIUM_ARB) ss <<
"Medium";
64 else if(source == GL_DEBUG_SEVERITY_LOW_ARB) ss <<
"Low";
66 string severityStr = ss.str();
71 string idStr = ss.str();
76 string msgStr = ss.str();
80 cerr <<
"ERROR: An OpenGL error occurred(" << sourceStr <<
";" << typeStr <<
";" << severityStr <<
";" << idStr <<
";" << msgStr <<
")" << endl;
87 , m_size(m_app->getConfig().resolution())
89 , m_hasProjChanged(2,true)
94 cerr <<
"ERROR: Failed to init GLFW." << endl;
100 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
101 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
102 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
104 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
107 GLFWmonitor* monitor =
nullptr;
110 monitor = glfwGetPrimaryMonitor();
114 auto mode = glfwGetVideoMode(monitor);
115 m_size.x = (float)mode->width;
116 m_size.y = (
float)mode->height;
123 cerr <<
"ERROR: Failed to open window." << endl;
128 glfwSetWindowUserPointer(
m_window,
this);
130 glfwSetInputMode(
m_window, GLFW_STICKY_KEYS, GL_TRUE);
131 glfwSetInputMode(
m_window, GLFW_STICKY_MOUSE_BUTTONS, GL_TRUE);
134 glfwSetInputMode(
m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
141 glewExperimental =
true;
142 if (glewInit() != GLEW_OK)
144 cerr <<
"ERROR: Failed to init GLEW." << endl;
150 if ( glDebugMessageCallbackARB )
153 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
171 auto wnd = (
Window*)glfwGetWindowUserPointer(window);
172 wnd->m_size = vec2(width,height);
173 wnd->onWindowSizeChanged();
194 auto wnd = (
Window*)glfwGetWindowUserPointer(window);
195 wnd->onKeyStateChanged(key, action == GLFW_PRESS);
204 auto wnd = (
Window*)glfwGetWindowUserPointer(window);
205 wnd->m_cursor = vec2((
float)x,(
float)y);
219 auto cursorDeltaInMotoSpace = vec2(0, 0);
223 cursorDeltaInMotoSpace = vec2(0,0);
227 cursorDeltaInMotoSpace =
m_cursor - cursor;
238 return !glfwWindowShouldClose(
m_window);
245 return glfwGetKey(
m_window, key) == GLFW_PRESS;
249 return glfwGetMouseButton(
m_window, button) == GLFW_PRESS;
254 glfwSetWindowShouldClose(
m_window,
true);
266 glfwSetCursorPos(
m_window, pos.x, pos.y);
vec2 calculateCursorPosInVisualSpace(vec2 cursorPosBeforeMove, vec2 const &deltaMotorSpace)
Configuration & getConfig()
void APIENTRY debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam)
void glfwOnKeyStateChanged(GLFWwindow *window, int key, int scancode, int action, int mods)
vector< bool > m_hasProjChanged
void onWindowSizeChanged(bool initialization=false)
void onKeyStateChanged(int key, bool pressed)
friend void glfwOnKeyStateChanged(GLFWwindow *window, int key, int scancode, int action, int mods)
bool hasResolution() const
void glfwOnError(int errorCode, const char *desc)
void updatePointerPosition(vec2 pos)
void update(double time, double timeDelta)
void glfwOnCursorMove(GLFWwindow *window, double x, double y)
OwnCursor & getOwnCursor()
void onWindowSizeChanged(vec2 const &size)
bool isFullScreen() const
void onKeyStateChanged(int key, bool pressed)
string const & windowTitle() const
friend void glfwOnWindowSizeChanged(GLFWwindow *window, int width, int height)
void glfwOnWindowSizeChanged(GLFWwindow *window, int width, int height)
friend void glfwOnCursorMove(GLFWwindow *window, double x, double y)