FBO draw to screen ok, now for modyfing the texture
This commit is contained in:
parent
c5b2dd897b
commit
640244c556
@ -95,7 +95,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalLibraryDirectories>C:\Graphics\Tools\SOIL\lib;C:\Graphics\Tools\Assimp\lib\x86;C:\Graphics\Tools\glfw\lib\x86;C:\Graphics\Tools\glew\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>assimp.lib;SOIL.lib;glfw3.lib;glew32.lib;opengl32.lib;FreeImage.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>assimp.lib;SOIL.lib;glfw3.lib;glew32.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
||||
@ -2,26 +2,32 @@
|
||||
|
||||
Multipass::Multipass() : _quad_shader("textureViewer.vert", "textureViewer.frag")
|
||||
{
|
||||
|
||||
_draw_buffers_size = 0;
|
||||
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()
|
||||
@ -32,6 +38,7 @@ 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);
|
||||
@ -44,8 +51,8 @@ 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);
|
||||
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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -17,8 +17,6 @@ float LinearizeDepth(in vec2 uv)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
//rrra because depth textures are not usual textures, they have only one channel
|
||||
@ -29,6 +27,5 @@ void main()
|
||||
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);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user