From c5ed6f9b9e41af32b33b232ed1a852f3ed44fecf Mon Sep 17 00:00:00 2001 From: Harry Date: Tue, 21 Mar 2017 20:04:58 +0000 Subject: [PATCH] Added preliminary support to Render-To-Texture via setRenderTarget() functions for both Texture and Window --- res/runtime/resources.data | 4 +++- src/test.cpp | 1 + src/texture.cpp | 5 +++++ src/texture.hpp | 1 + src/window.cpp | 6 ++++++ src/window.hpp | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/res/runtime/resources.data b/res/runtime/resources.data index 22f5fd6f5d..2aea7edb82 100644 --- a/res/runtime/resources.data +++ b/res/runtime/resources.data @@ -77,4 +77,6 @@ speed: 2.5 -played: 117303 + + +played: 117352 diff --git a/src/test.cpp b/src/test.cpp index 01528437ba..21e6bc4bc4 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -75,6 +75,7 @@ int main() std::cout << "Camera Position = [" << cam.getPosR().getX() << ", " << cam.getPosR().getY() << ", " << cam.getPosR().getZ() << "].\n"; std::cout << "Lifetime Spent: " << secondsLifetime << " seconds.\n"; } + wnd.setRenderTarget(); fpscounter.update(); deltaTotal += fpscounter.getRange(); deltas.push_back(fpscounter.getRange()); diff --git a/src/texture.cpp b/src/texture.cpp index a7e5848aeb..30e0317f75 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -66,6 +66,11 @@ void Texture::bind(GLuint shaderProgram, unsigned int id) glUniform1i(this->textureID, id); } +void Texture::setRenderTarget() const +{ + +} + std::string Texture::getFileName() const { return this->filename; diff --git a/src/texture.hpp b/src/texture.hpp index cbc9c5152f..cf67474f6d 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -18,6 +18,7 @@ class Texture Texture(std::string filename = "./res/textures/undefined.jpg"); ~Texture(); void bind(GLuint shaderProgram, unsigned int id); + void setRenderTarget() const; std::string getFileName() const; static std::shared_ptr getFromLink(std::string textureLink, std::vector> allTextures); protected: diff --git a/src/window.cpp b/src/window.cpp index ad5b3540d5..df9f242235 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -67,6 +67,12 @@ void Window::setTitle(std::string newTitle) SDL_SetWindowTitle(this->wnd, newTitle.c_str()); } +void Window::setRenderTarget() const +{ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glViewport(0, 0, this->w, this->h); +} + void Window::clear(float r, float g, float b, float a) const { glClearColor(r, g, b, a); diff --git a/src/window.hpp b/src/window.hpp index d9d65e28c5..1d4ad6f39f 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -31,6 +31,7 @@ class Window bool isCloseRequested() const; void requestClose(); void setTitle(std::string newTitle); + void setRenderTarget() const; void clear(float r = 1.0f, float g = 1.0f, float b = 1.0f, float a = 1.0f) const; void update();