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.

50 lines
1.6 KiB

  1. #include "scene.h"
  2. #include "utils.h"
  3. #include "model.h"
  4. #include "framebufferobject.h"
  5. #include "fullscreenquad.h"
  6. glm::mat4 viewMatrix, projectionMatrix;
  7. glm::vec3 cameraPos(4.0f, 3.0f, 4.0f);
  8. Model model;
  9. FrameBufferObject *fbo;
  10. FullScreenQuad *fsq;
  11. void Init()
  12. {
  13. model.Init("Res/Sphere.obj");
  14. model.mShader->Init("Res/diffuse_vs.vs", "Res/diffuse_vs.fs");
  15. model.SetPosition(0.0f, 0.0f, 0.0f);
  16. model.SetAmbientMaterial(0.1f, 0.1f, 0.1f, 1.0f);
  17. model.mShader->SetVec4("U_AmbientLight", 0.1f, 0.1f, 0.1f, 1.0f);
  18. model.SetDiffuseMaterial(0.4f, 0.4f, 0.4f, 1.0f);
  19. model.mShader->SetVec4("U_DiffuseLight", 0.8f, 0.8f, 0.8f, 1.0f);
  20. model.mShader->SetVec4("U_LightPos", 0.0f, 1.0f, 0.0f, 0.0f);
  21. viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
  22. fsq = new FullScreenQuad();
  23. fsq->Init();
  24. fsq->mShader->Init("Res/fullscreenquad.vs", "Res/fullscreenquad.fs");
  25. }
  26. void SetViewPortSize(float width, float height)
  27. {
  28. projectionMatrix = glm::perspective(50.0f, width/height, 0.1f, 1000.0f);
  29. fbo = new FrameBufferObject();
  30. fbo->AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, (int)width, (int)height);
  31. fbo->AttachDepthBuffer("depth", (int)width, (int)height);
  32. fbo->Finish();
  33. fbo->Bind();
  34. glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
  35. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  36. model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
  37. fbo->Unbind();
  38. }
  39. void Draw()
  40. {
  41. glClearColor(0.0f,0.0f,0.0f,1.0f);
  42. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  43. fsq->mShader->SetTexture("U_Texture", fbo->GetBuffer("color"));
  44. fsq->Draw();
  45. }