diff --git a/BaseGLProject/BaseGLProject.vcxproj b/BaseGLProject/BaseGLProject.vcxproj index e4f9ed4..086a1b7 100644 --- a/BaseGLProject/BaseGLProject.vcxproj +++ b/BaseGLProject/BaseGLProject.vcxproj @@ -95,7 +95,7 @@ true Console C:\Graphics\Tools\SOIL\lib;C:\Graphics\Tools\Assimp\lib\x86;C:\Graphics\Tools\glfw\lib\x86;C:\Graphics\Tools\glew\lib;%(AdditionalLibraryDirectories) - assimp.lib;SOIL.lib;glfw3.lib;glew32.lib;opengl32.lib;FreeImage.lib;%(AdditionalDependencies) + assimp.lib;SOIL.lib;glfw3.lib;glew32.lib;opengl32.lib;%(AdditionalDependencies) diff --git a/BaseGLProject/Multipass.cpp b/BaseGLProject/Multipass.cpp index efd2f76..9936022 100644 --- a/BaseGLProject/Multipass.cpp +++ b/BaseGLProject/Multipass.cpp @@ -2,26 +2,32 @@ Multipass::Multipass() : _quad_shader("textureViewer.vert", "textureViewer.frag") { + _draw_buffers_size = 0; - glGenFramebuffers(1, &_fboId); + glGenFramebuffers(1, &_fboId); glBindFramebuffer(GL_FRAMEBUFFER, _fboId); _createQuad(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } void Multipass::setDrawBuffers() -{ +{ + glBindFramebuffer(GL_FRAMEBUFFER, _fboId); glDrawBuffers(_draw_buffers_size, _draw_buffers); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) throw std::runtime_error("Error during framebuffer initialisation"); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } void Multipass::bindToFrameBuffer(GLenum type, GLenum texture, std::string texName) { + glBindFramebuffer(GL_FRAMEBUFFER, _fboId); glFramebufferTexture2D(GL_FRAMEBUFFER, type, texture, _pass_textures[texName], 0); if (type != GL_DEPTH_ATTACHMENT) { _draw_buffers[_draw_buffers_size] = type; _draw_buffers_size++; } + glBindFramebuffer(GL_FRAMEBUFFER, 0); } Multipass::~Multipass() @@ -31,7 +37,8 @@ Multipass::~Multipass() void Multipass::addTexture(const std::string & tex_name, GLuint filter, GLuint type, GLuint type_2, bool depth, SceneContext &scnctx) -{ +{ + glBindFramebuffer(GL_FRAMEBUFFER, _fboId); glGenTextures(1, &_pass_textures[tex_name]);; glBindTexture(GL_TEXTURE_2D, _pass_textures[tex_name]); glTexImage2D(GL_TEXTURE_2D, 0, type, scnctx.width, scnctx.height, 0, type_2, GL_FLOAT, 0); @@ -43,9 +50,9 @@ void Multipass::addTexture(const std::string & tex_name, GLuint filter, GLuint t { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - } - - glBindTexture(GL_TEXTURE_2D, 0); + } + glBindTexture(GL_TEXTURE_2D, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } void Multipass::enableFrameBufferTexture(const std::string tex_name) @@ -63,7 +70,7 @@ void Multipass::drawResultToScreen(SceneContext & scnctx) _quad_shader.enable(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _pass_textures[_current_tex]); - _quad_shader.addUniform("tex", (int)_pass_textures[_current_tex]); + _quad_shader.addUniform("tex", 0); glBindVertexArray(_quad_vao); glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); diff --git a/BaseGLProject/MyGLWindow.cpp b/BaseGLProject/MyGLWindow.cpp index cf0e2a8..bc6affb 100644 --- a/BaseGLProject/MyGLWindow.cpp +++ b/BaseGLProject/MyGLWindow.cpp @@ -1,5 +1,4 @@ #include "MyGlWindow.h" -#include "..\..\..\..\Downloads\FreeImage3180Win32Win64\FreeImage\Dist\x32\FreeImage.h" //Getting the projection matrix glm::mat4x4 perspective(float fovy, float aspect, float near, float far) { @@ -135,9 +134,9 @@ void MyGlWindow::multipassSetup() _multipassManager.addTexture("render_tex", GL_NEAREST, GL_RGB, GL_RGB, false, _scnctx); _multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, "render_tex"); - //_multipassManager.addTexture("depth_tex", GL_LINEAR, GL_DEPTH_COMPONENT24, - // GL_DEPTH_COMPONENT, true, _scnctx); - //_multipassManager.bindToFrameBuffer(GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, "depth_tex"); + _multipassManager.addTexture("depth_tex", GL_LINEAR, GL_DEPTH_COMPONENT24, + GL_DEPTH_COMPONENT, true, _scnctx); + _multipassManager.bindToFrameBuffer(GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, "depth_tex"); _multipassManager.setDrawBuffers(); } @@ -154,6 +153,7 @@ void MyGlWindow::setup() skybox.scale = 10; _scnctx.skybox_tex = skybox.getTexID(); lightSetup(); + multipassSetup(); //meshes.emplace("Ogre", new Mesh("ogre/ogre.obj", shaders["TexNmapLight"])); //meshes["Ogre"]->addTranslation(glm::vec4(-0.5, 1, 0, 0)); @@ -210,7 +210,6 @@ void MyGlWindow::setup() //meshes.emplace("Teapot", new Mesh("teapot.obj", shaders["Skybox"])); - multipassSetup(); } void MyGlWindow::draw() @@ -237,22 +236,8 @@ void MyGlWindow::draw() for (auto it = meshes.begin(); it != meshes.end(); it++) (*it).second->draw(_scnctx); - //_multipassManager.drawResultToScreen(_scnctx); + _multipassManager.drawResultToScreen(_scnctx); //skybox.draw(shaders["Skybox"], _scnctx); - - - BYTE* pixels = new BYTE[3 * _scnctx.width * _scnctx.height]; - - glReadPixels(0, 0, _scnctx.width, _scnctx.height, GL_RGB, GL_UNSIGNED_BYTE, pixels); - - // Convert to FreeImage format & save to file - FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, _scnctx.width, _scnctx.height, 3 * _scnctx.width, 24, 0x0000FF, 0xFF0000, 0x00FF00, false); - FreeImage_Save(FIF_BMP, image, "D:/Users/Hurlu/Desktop/bitmap.bmp", 0); - - // Free resources - FreeImage_Unload(image); - delete[] pixels; - exit(0); } diff --git a/BaseGLProject/textureViewer.frag b/BaseGLProject/textureViewer.frag index dcbfa88..edde5ac 100644 --- a/BaseGLProject/textureViewer.frag +++ b/BaseGLProject/textureViewer.frag @@ -17,8 +17,6 @@ float LinearizeDepth(in vec2 uv) } - - void main() { //rrra because depth textures are not usual textures, they have only one channel @@ -28,7 +26,6 @@ void main() float d; d = LinearizeDepth(uv); final_color = vec4(d,d,d,1.0); - } - final_color = texture(tex, uv).rgba; + } //final_color = vec4(1.0,0.0,0.0,1.0); } \ No newline at end of file