From 85f7511207e1eb9031a6915a1498fea108caa038 Mon Sep 17 00:00:00 2001 From: blobt Date: Mon, 21 Sep 2020 11:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0fullscreenquad=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fullscreenquad.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++ fullscreenquad.h | 17 ++++++++ shader.cpp | 9 +---- 3 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 fullscreenquad.cpp create mode 100644 fullscreenquad.h diff --git a/fullscreenquad.cpp b/fullscreenquad.cpp new file mode 100644 index 0000000..112671d --- /dev/null +++ b/fullscreenquad.cpp @@ -0,0 +1,96 @@ +#include "fullscreenquad.h" + +void FullScreenQuad::Init() +{ + mVertexBuffer = new VertexBuffer(); + mVertexBuffer->SetSize(4); + mVertexBuffer->SetTexcoord(0, 0.0f, 0.0f); + mVertexBuffer->SetTexcoord(1, 1.0f, 0.0f); + mVertexBuffer->SetTexcoord(2, 0.0f, 1.0f); + mVertexBuffer->SetTexcoord(3, 1.0f, 1.0f); + mShader = new Shader(); +} + +void FullScreenQuad::Draw() { + //µ¥Î»¾ØÕó + float identity[] = { + 1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f, + }; + mVertexBuffer->SetPosition(0, -1.0f, -1.0f, 0.0f); + mVertexBuffer->SetPosition(1, 1.0f, -1.0f, 0.0f); + mVertexBuffer->SetPosition(2, -1.0f, 1.0f, 0.0f); + mVertexBuffer->SetPosition(3, 1.0f, 1.0f, 0.0f); + mVertexBuffer->Bind(); + mShader->Bind(identity, identity, identity); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + mVertexBuffer->Unbind(); +} +void FullScreenQuad::DrawToLeftTop() { + float identity[] = { + 1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f, + }; + mVertexBuffer->SetPosition(0, -1.0f, 0.0f, -1.0f); + mVertexBuffer->SetPosition(1, 0.0f, 0.0f, -1.0f); + mVertexBuffer->SetPosition(2, -1.0f, 1.0f, -1.0f); + mVertexBuffer->SetPosition(3, 0.0f, 1.0f, -1.0f); + mVertexBuffer->Bind(); + mShader->Bind(identity, identity, identity); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + mVertexBuffer->Unbind(); +} +void FullScreenQuad::DrawToLeftBottom() { + float identity[] = { + 1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f, + }; + mVertexBuffer->SetPosition(0, -1.0f, -1.0f, -1.0f); + mVertexBuffer->SetPosition(1, 0.0f, -1.0f, -1.0f); + mVertexBuffer->SetPosition(2, -1.0f, 0.0f, -1.0f); + mVertexBuffer->SetPosition(3, 0.0f, 0.0f, -1.0f); + mVertexBuffer->Bind(); + mShader->Bind(identity, identity, identity); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + mVertexBuffer->Unbind(); +} + +void FullScreenQuad::DrawToRightTop() { + float identity[] = { + 1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f, + }; + mVertexBuffer->SetPosition(0, 0.0f, 0.0f, -1.0f); + mVertexBuffer->SetPosition(1, 1.0f, 0.0f, -1.0f); + mVertexBuffer->SetPosition(2, 0.0f, 1.0f, -1.0f); + mVertexBuffer->SetPosition(3, 1.0f, 1.0f, -1.0f); + mVertexBuffer->Bind(); + mShader->Bind(identity, identity, identity); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + mVertexBuffer->Unbind(); +} + +void FullScreenQuad::DrawToRightBottom() { + float identity[] = { + 1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f, + }; + mVertexBuffer->SetPosition(0, 0.0f, -1.0f, -1.0f); + mVertexBuffer->SetPosition(1, 1.0f, -1.0f, -1.0f); + mVertexBuffer->SetPosition(2, 0.0f, 0.0f, -1.0f); + mVertexBuffer->SetPosition(3, 1.0f, 0.0f, -1.0f); + mVertexBuffer->Bind(); + mShader->Bind(identity, identity, identity); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + mVertexBuffer->Unbind(); +} \ No newline at end of file diff --git a/fullscreenquad.h b/fullscreenquad.h new file mode 100644 index 0000000..c92dc16 --- /dev/null +++ b/fullscreenquad.h @@ -0,0 +1,17 @@ +#pragma once +#include "ggl.h" +#include "vertexbuffer.h" +#include "shader.h" + +class FullScreenQuad { +public: + VertexBuffer *mVertexBuffer; + Shader *mShader; +public: + void Init(); + void Draw(); + void DrawToLeftTop(); + void DrawToRightTop(); + void DrawToLeftBottom(); + void DrawToRightBottom(); +}; \ No newline at end of file diff --git a/shader.cpp b/shader.cpp index 92cbd41..31c9acb 100644 --- a/shader.cpp +++ b/shader.cpp @@ -183,11 +183,4 @@ GLuint Shader::SetTextureCube(const char * name, GLuint texture) { iter->second->mTexture = texture; } return oldTexture; -} - - - - - - - +} \ No newline at end of file