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.
90 lines
3.0 KiB
90 lines
3.0 KiB
#include "scene.h"
|
|
#include "ggl.h"
|
|
#include "utils.h"
|
|
#include "ground.h"
|
|
#include "shader.h"
|
|
#include "model.h"
|
|
#include "skybox.h"
|
|
#include "particleSystem.h"
|
|
#include "framebufferobject.h"
|
|
|
|
glm::mat4 modelMatrix, viewMatrix, projectionMatrix;
|
|
glm::vec3 cameraPos(10.0f, 10.0f, 10.0f);
|
|
Ground ground;
|
|
Model model, niutou, sphere;
|
|
SkyBox skybox;
|
|
ParticleSystem ps;
|
|
FrameBufferObject *fbo;
|
|
VertexBuffer *fsqVertex;
|
|
Shader *fsqShader;
|
|
glm::mat4 fsqViewMatrix;
|
|
|
|
void Init() {
|
|
viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f,1.0f,0.0f));
|
|
|
|
ground.Init();
|
|
|
|
model.Init("Res/Sphere.obj");
|
|
model.SetTexture("Res/earth.bmp");
|
|
model.SetPosition(0.0f, 0.0f, 0.0f);
|
|
skybox.Init("Res/");
|
|
niutou.Init("Res/niutou.obj");
|
|
niutou.SetTexture("Res/niutou.bmp");
|
|
niutou.mModelMatrix = glm::translate(-5.0f, 0.0f, 4.0f)*glm::scale(0.05f, 0.05f, 0.05f);
|
|
ps.Init(0.0f, 0.0f, 0.0f);
|
|
}
|
|
void SetViewPortSize(float width, float height) {
|
|
projectionMatrix = glm::perspective(60.0f, width / height, 0.1f, 1000.0f);
|
|
|
|
fbo = new FrameBufferObject;
|
|
fbo->AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, (int)width, (int)height);
|
|
fbo->AttachColorBuffer("color1", GL_COLOR_ATTACHMENT1, (int)width, (int)height);
|
|
fbo->AttachDepthBuffer("depth", (int)width, (int)height);
|
|
fbo->Finish();
|
|
|
|
sphere.Init("Res/Sphere.obj");
|
|
sphere.SetTexture(fbo->GetBuffer("color"));
|
|
sphere.mModelMatrix = glm::scale(4.0f, 4.0f, 4.0f)*glm::rotate(150.0f, 0.0f, 1.0f, 0.0f);
|
|
|
|
float aspect = width / height;
|
|
float halfFOV = 60.0f / 2.0f;
|
|
float randianHalfFOV = 3.14f*halfFOV / 180.0f;
|
|
float tanHalfFOV = sinf(randianHalfFOV) / cosf(randianHalfFOV);
|
|
float y = tanHalfFOV*0.2f;
|
|
float x = y*aspect;
|
|
fsqVertex = new VertexBuffer;
|
|
fsqVertex->SetSize(4);
|
|
fsqVertex->SetPosition(0, -x, -y, -0.2f);
|
|
fsqVertex->SetTexcoord(0, 0.0f, 0.0f);
|
|
fsqVertex->SetPosition(1, x, -y, -0.2f);
|
|
fsqVertex->SetTexcoord(1, 1.0f, 0.0f);
|
|
fsqVertex->SetPosition(2, -x, y, -0.2f);
|
|
fsqVertex->SetTexcoord(2, 0.0f, 1.0f);
|
|
fsqVertex->SetPosition(3, x, y, -0.2f);
|
|
fsqVertex->SetTexcoord(3, 1.0f, 1.0f);
|
|
|
|
fsqShader = new Shader;
|
|
fsqShader->Init("Res/texture.vs", "Res/texture.fs");
|
|
fsqShader->SetTexture("U_Texture", fbo->GetBuffer("color"));
|
|
}
|
|
void Draw() {
|
|
float frameTime = GetFrameTime();
|
|
glClearColor(0.1f, 0.4f, 0.6f, 1.0f);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
fbo->Bind();
|
|
skybox.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
|
|
ground.Draw(viewMatrix, projectionMatrix);
|
|
model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
|
|
niutou.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
|
|
ps.Update(frameTime);
|
|
ps.Draw(viewMatrix, projectionMatrix);
|
|
fbo->Unbind();
|
|
|
|
//sphere.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
|
|
|
|
fsqVertex->Bind();
|
|
fsqShader->Bind(glm::value_ptr(modelMatrix), glm::value_ptr(fsqViewMatrix), glm::value_ptr(projectionMatrix));
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, fsqVertex->mVertexCount);
|
|
fsqVertex->Unbind();
|
|
}
|