From 5617f8f2bae9a0f924f17865d72165677ec450f4 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Thu, 25 Jun 2015 20:02:20 +0200 Subject: [PATCH] Window is now resizeable --- Weave/Game.cpp | 3 +++ Weave/Graphix/Graphix.cpp | 8 ++++---- Weave/Graphix/ViewPort.cpp | 15 ++++++++++++++- Weave/Graphix/ViewPort.h | 4 +++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Weave/Game.cpp b/Weave/Game.cpp index f44fe4a..486b0b0 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -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); diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index 4158838..961ed2d 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -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); diff --git a/Weave/Graphix/ViewPort.cpp b/Weave/Graphix/ViewPort.cpp index 904f4bb..80f68b8 100644 --- a/Weave/Graphix/ViewPort.cpp +++ b/Weave/Graphix/ViewPort.cpp @@ -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); +} diff --git a/Weave/Graphix/ViewPort.h b/Weave/Graphix/ViewPort.h index 02c4a9a..1ea3588 100644 --- a/Weave/Graphix/ViewPort.h +++ b/Weave/Graphix/ViewPort.h @@ -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; -- 2.47.3