]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
Window is now resizeable
authorPeter Schaefer <schaeferpm@gmail.com>
Thu, 25 Jun 2015 18:02:20 +0000 (20:02 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Thu, 25 Jun 2015 18:02:20 +0000 (20:02 +0200)
Weave/Game.cpp
Weave/Graphix/Graphix.cpp
Weave/Graphix/ViewPort.cpp
Weave/Graphix/ViewPort.h

index f44fe4a0beefb7585327f7890ac49d0f69a97a1e..486b0b0798002c64c5a749cf1b08fbaccf19782d 100644 (file)
@@ -119,6 +119,9 @@ void Game::play()
 
 void Game::update(float deltaT)
 {
+
+       if (Graphix::getWindowHeight() != current_world->getViewport().getHeight() || Graphix::getWindowWidth() != current_world->getViewport().getWidth())
+               current_world->getViewport().setView(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight());
        if (playing){
                current_world->update(deltaT);
                
index 415883817a424a7b288f53b21a30573602ae4295..961ed2d82363ab9d6e8ec291f147d7a6dedbc2e6 100644 (file)
@@ -57,10 +57,10 @@ void Graphix::init()
 
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
-       //SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 16);
-       //SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 16);
-       //SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 16);
-       //SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 16);
+       SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 16);
+       SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 16);
+       SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 16);
+       SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 16);
 
        sdl_window = SDL_CreateWindow(windowTitle.c_str(), xpos, ypos, width, height, windowFlags);
 
index 904f4bb5df304f8cf198be336759ac11b5f67bc7..80f68b845297bbc6c923943f5d6943bb768375a3 100644 (file)
@@ -9,11 +9,14 @@
 #define VIEW_BOT_LIM -0.3f
 
 
-ViewPort::ViewPort(unsigned int _x, unsigned int _y, unsigned int _width, unsigned int _height, float fovy, float zNear, float zFar) :
+ViewPort::ViewPort(unsigned int _x, unsigned int _y, unsigned int _width, unsigned int _height, float _fovy, float _zNear, float _zFar) :
        xpos(_x),
        ypos(_y),
        width(_width),
        height(_height),
+       fovy(_fovy),
+       zNear(_zNear),
+       zFar(_zFar),
        projection(perspective(fovy, (float)width / height, zNear, zFar)),
        view_angle_x(0),
        view_angle_y(0),
@@ -109,3 +112,13 @@ unsigned int ViewPort::getHeight() const
 {
        return height;
 }
+
+void ViewPort::setView(uint _x, uint _y, uint _width, uint _height, bool _updateProjection)
+{
+       xpos = _x;
+       ypos = _y;
+       width = _width;
+       height = _height;
+       if (_updateProjection)
+               projection = perspective(fovy, (float)width / height, zNear, zFar);
+}
index 02c4a9aa2246e7de516693abd5b2615e91f74e93..1ea35884183d2207cadab831d74ff71c4ad5ee41 100644 (file)
@@ -13,7 +13,7 @@ public:
 
        void useViewPort() const;
 
-       void setView(unsigned int width, unsigned int height);
+       void setView(unsigned int x, unsigned int y, unsigned int width, unsigned int height, bool updateProjection = true);
 
        void bindView(Shader* shader) const;
        void bindView(Shader* shader, vec3 lookat) const;
@@ -36,6 +36,8 @@ protected:
        unsigned int xpos;
        unsigned int ypos;
 
+       float fovy, zNear, zFar;
+
        mat4 projection;
        mat4 view;