|
|
#include "scene.h"
#include "utils.h"
#include "model.h"
#include "framebufferobject.h"
#include "fullscreenquad.h"
glm::mat4 viewMatrix, projectionMatrix; glm::vec3 cameraPos(4.0f, 3.0f, 4.0f); Model model; FrameBufferObject *fbo; FullScreenQuad *fsq;
void Init() { model.Init("Res/Sphere.obj"); model.mShader->Init("Res/diffuse_vs.vs", "Res/diffuse_vs.fs"); model.SetPosition(0.0f, 0.0f, 0.0f); model.SetAmbientMaterial(0.1f, 0.1f, 0.1f, 1.0f); model.mShader->SetVec4("U_AmbientLight", 0.1f, 0.1f, 0.1f, 1.0f); model.SetDiffuseMaterial(0.4f, 0.4f, 0.4f, 1.0f); model.mShader->SetVec4("U_DiffuseLight", 0.8f, 0.8f, 0.8f, 1.0f); model.mShader->SetVec4("U_LightPos", 0.0f, 1.0f, 0.0f, 0.0f); viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); fsq = new FullScreenQuad(); fsq->Init(); fsq->mShader->Init("Res/fullscreenquad.vs", "Res/fullscreenquad.fs"); }
void SetViewPortSize(float width, float height) { projectionMatrix = glm::perspective(50.0f, width/height, 0.1f, 1000.0f); fbo = new FrameBufferObject(); fbo->AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, (int)width, (int)height); fbo->AttachDepthBuffer("depth", (int)width, (int)height); fbo->Finish();
fbo->Bind(); glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z); fbo->Unbind(); }
void Draw() { glClearColor(0.0f,0.0f,0.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); fsq->mShader->SetTexture("U_Texture", fbo->GetBuffer("color")); fsq->Draw(); }
|