diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index 700f2f9..cddf3cc 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -20,16 +20,16 @@ glm::vec3 FrameBuffer::getResolutionFromParameters(int ar, int h) return res; } -FrameBuffer::FrameBuffer(glm::vec3 resolution): textureid_(0), framebufferid_(0), usedepth_(false) +FrameBuffer::FrameBuffer(glm::vec3 resolution, bool useAlpha, bool useDepthBuffer): textureid_(0), framebufferid_(0), usealpha_(useAlpha), usedepth_(useDepthBuffer) { attrib_.viewport = glm::ivec2(resolution); - attrib_.clear_color = glm::vec4(0.f,0.f,0.f,1.f); + attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, usealpha_ ? 0.f : 1.f); } -FrameBuffer::FrameBuffer(uint width, uint height, bool useDepthBuffer): textureid_(0), framebufferid_(0), usedepth_(useDepthBuffer) +FrameBuffer::FrameBuffer(uint width, uint height, bool useAlpha, bool useDepthBuffer): textureid_(0), framebufferid_(0), usealpha_(useAlpha), usedepth_(useDepthBuffer) { attrib_.viewport = glm::ivec2(width, height); - attrib_.clear_color = glm::vec4(0.f,0.f,0.f,1.f); + attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, usealpha_ ? 0.f : 1.f); } void FrameBuffer::init() @@ -50,9 +50,16 @@ void FrameBuffer::init() // generate texture glGenTextures(1, &textureid_); glBindTexture(GL_TEXTURE_2D, textureid_); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, attrib_.viewport.x, attrib_.viewport.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + if (usealpha_) + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, attrib_.viewport.x, attrib_.viewport.y, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + else + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, attrib_.viewport.x, attrib_.viewport.y, + 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, 0); // attach the texture to FBO color attachment point diff --git a/FrameBuffer.h b/FrameBuffer.h index 016cbad..093bc4e 100644 --- a/FrameBuffer.h +++ b/FrameBuffer.h @@ -14,8 +14,8 @@ public: static float resolution_height[4]; static glm::vec3 getResolutionFromParameters(int ar, int h); - FrameBuffer(glm::vec3 resolution); - FrameBuffer(uint width, uint height, bool useDepthBuffer = false); + FrameBuffer(glm::vec3 resolution, bool useAlpha = false, bool useDepthBuffer = false); + FrameBuffer(uint width, uint height, bool useAlpha = false, bool useDepthBuffer = false); ~FrameBuffer(); // bind the FrameBuffer as current to draw into @@ -50,7 +50,7 @@ private: RenderingAttrib attrib_; uint textureid_; uint framebufferid_; - bool usedepth_; + bool usealpha_, usedepth_; }; diff --git a/MediaSource.cpp b/MediaSource.cpp index 841f999..7a637ac 100644 --- a/MediaSource.cpp +++ b/MediaSource.cpp @@ -70,7 +70,7 @@ void MediaSource::init() // create Frame buffer matching size of media player float height = float(mediaplayer()->width()) / mediaplayer()->aspectRatio(); - renderbuffer_ = new FrameBuffer(mediaplayer()->width(), (uint)height); + renderbuffer_ = new FrameBuffer(mediaplayer()->width(), (uint)height, true); // create the surfaces to draw the frame buffer in the views // TODO Provide the source custom effect shader diff --git a/Primitives.cpp b/Primitives.cpp index afb93df..f57afca 100644 --- a/Primitives.cpp +++ b/Primitives.cpp @@ -28,7 +28,13 @@ static const std::vector square_points { Surface::Surface(Shader *s) : Primitive(s), textureindex_(0) { - // geometry + // geometry for a trianglulated simple rectangle surface with UV + // (0,0) B +---+ D (1,0) + // |\ | + // | \ | + // | \| + // (0,1) A +---+ C (1,1) + points_ = std::vector { glm::vec3( -1.f, -1.f, 0.f ), glm::vec3( -1.f, 1.f, 0.f ), glm::vec3( 1.f, -1.f, 0.f ), glm::vec3( 1.f, 1.f, 0.f ) }; colors_ = std::vector { glm::vec4( 1.f, 1.f, 1.f , 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ), diff --git a/SessionSource.cpp b/SessionSource.cpp index 13230d4..b569462 100644 --- a/SessionSource.cpp +++ b/SessionSource.cpp @@ -107,8 +107,7 @@ void SessionSource::init() sessionsurface_->setTextureIndex( session_->frame()->texture() ); // create Frame buffer matching size of session - renderbuffer_ = new FrameBuffer(session_->frame()->resolution()); - renderbuffer_->setClearColor(glm::vec4(0.f, 0.f, 0.f, 1.f)); + renderbuffer_ = new FrameBuffer( session_->frame()->resolution()); // create the surfaces to draw the frame buffer in the views rendersurface_ = new FrameBufferSurface(renderbuffer_, blendingshader_); diff --git a/Source.cpp b/Source.cpp index b207c89..1824943 100644 --- a/Source.cpp +++ b/Source.cpp @@ -238,8 +238,7 @@ void RenderSource::init() sessionsurface_->setTextureIndex( session->frame()->texture() ); // create Frame buffer matching size of session - renderbuffer_ = new FrameBuffer( session->frame()->resolution() ); - renderbuffer_->setClearColor(glm::vec4(0.f, 0.f, 0.f, 1.f)); + renderbuffer_ = new FrameBuffer( session->frame()->resolution()); // create the surfaces to draw the frame buffer in the views rendersurface_ = new FrameBufferSurface(renderbuffer_, blendingshader_); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 95728e9..adb085a 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -618,7 +618,7 @@ void UserInterface::RenderPreview() float width = ImGui::GetContentRegionAvail().x; ImVec2 imagesize ( width, width / ar); - ImGui::Image((void*)(intptr_t)output->texture(), imagesize, ImVec2(0.f, 0.f), ImVec2(1.f, -1.f)); + ImGui::Image((void*)(intptr_t)output->texture(), imagesize, ImVec2(0.f, 1.f), ImVec2(1.f, 0.f)); ImGui::End(); } diff --git a/View.cpp b/View.cpp index 73d7339..dd283b2 100644 --- a/View.cpp +++ b/View.cpp @@ -202,12 +202,11 @@ void RenderView::setResolution(glm::vec3 resolution) delete frame_buffer_; frame_buffer_ = new FrameBuffer(resolution); - frame_buffer_->setClearColor(glm::vec4(0.f, 0.f, 0.f, 1.f)); } void RenderView::draw() { - static glm::mat4 projection = glm::ortho(-1.f, 1.f, -1.f, 1.f, -SCENE_DEPTH, 0.f); + static glm::mat4 projection = glm::ortho(-1.f, 1.f, -1.f, 1.f, -SCENE_DEPTH, 1.f); glm::mat4 P = glm::scale( projection, glm::vec3(1.f / frame_buffer_->aspectRatio(), 1.f, 1.f)); frame_buffer_->begin(); scene.root()->draw(glm::identity(), P);