From 3ddcb72d5aa2fb3ad14e312835f233a8c1e9c9be Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sat, 15 Nov 2014 15:19:48 +0100 Subject: [PATCH] Reenabling resizeCallback. --- graphics.cc | 9 +-------- graphics.hh | 4 ---- main.cc | 11 ++++++++--- main.hh | 1 + 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/graphics.cc b/graphics.cc index 99a0ae7..72550d7 100644 --- a/graphics.cc +++ b/graphics.cc @@ -68,7 +68,7 @@ bool Graphics::createWindow() glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, true ); // define whether the window can get resized: - glfwWindowHint(GLFW_RESIZABLE, false); + glfwWindowHint(GLFW_RESIZABLE, true); // non-decorated windows can be used as splash screens: //glfwWindowHint( GLFW_DECORATED, false ); @@ -142,13 +142,6 @@ void Graphics::setWindowSize(glm::uvec2 windowSize) { this->windowSize = windowSize; } -void resizeCallback(Graphics* graphics, int newWidth, int newHeight) -{ - // store the new window size and adjust the viewport: - graphics->setWindowSize(glm::uvec2( newWidth, newHeight)); - glViewport( 0, 0, newWidth, newHeight); -} - glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, float aspectRatio) { float phiHalfInRadians = 0.5*phiInDegree * (M_PI/180.0); diff --git a/graphics.hh b/graphics.hh index c161227..a1b451d 100644 --- a/graphics.hh +++ b/graphics.hh @@ -11,8 +11,6 @@ class Graphics { Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane); Graphics(); void render(Level* level, ACGL::OpenGL::SharedShaderProgram shader); - // gets called at window resize: - void resizeCallback( GLFWwindow *, int newWidth, int newHeight ); // to build the projection matrix: glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio); glm::mat4 buildViewMatrix(Level* level); @@ -28,6 +26,4 @@ class Graphics { GLFWwindow* window; }; -void resizeCallback(Graphics* graphics, int newWidth, int newHeight); - #endif diff --git a/main.cc b/main.cc index 282cffe..ad8a43a 100644 --- a/main.cc +++ b/main.cc @@ -16,8 +16,6 @@ #include #include -Application app; - Application::Application() { graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 100.0f); } @@ -62,6 +60,13 @@ void Application::init() openGLCriticalError(); } +void resizeCallback(GLFWwindow* window, int newWidth, int newHeight) +{ + // store the new window size and adjust the viewport: + app.getGraphics()->setWindowSize(glm::uvec2( newWidth, newHeight)); + glViewport( 0, 0, newWidth, newHeight); +} + static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int) { if (_key == GLFW_KEY_ESCAPE && _action == GLFW_PRESS) { @@ -95,7 +100,7 @@ int main( int argc, char *argv[] ) glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_STICKY_KEYS, 1); // Hide mouse cursor glfwSetInputMode(app.getGraphics()->getWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); - //glfwSetWindowSizeCallback(app.getGraphics(), resizeCallback); + glfwSetWindowSizeCallback(app.getGraphics()->getWindow(), resizeCallback); glfwSetKeyCallback(app.getGraphics()->getWindow(), keyCallback ); glfwSetScrollCallback(app.getGraphics()->getWindow(), scrollCallback ); diff --git a/main.hh b/main.hh index 17e8fad..469dd4b 100644 --- a/main.hh +++ b/main.hh @@ -25,4 +25,5 @@ class Application { ACGL::OpenGL::SharedShaderProgram shader; }; +Application app; #endif