You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
59 lines
1.8 KiB
#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", "Res/diffuse.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.mShader->SetVec4("U_LightPos", 0.0f, 1.0f, 0.0f, 0.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.SetSpecularMaterial(1.0f, 1.0f, 1.0f, 1.0f);
|
|
model.mShader->SetVec4("U_SpecualrLight", 1.0f, 1.0f, 1.0f, 1.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();
|
|
}
|