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.

45 lines
1.3 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/ambient_vs.vs", "Res/ambient_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. viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
  19. fsq = new FullScreenQuad();
  20. fsq->Init();
  21. fsq->mShader->Init("Res/fullscreenquad.vs", "Res/fullscreenquad.fs");
  22. }
  23. void SetViewPortSize(float width, float height)
  24. {
  25. projectionMatrix = glm::perspective(50.0f, width/height, 0.1f, 1000.0f);
  26. fbo = new FrameBufferObject();
  27. fbo->AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, (int)width, (int)height);
  28. fbo->AttachDepthBuffer("depth", (int)width, (int)height);
  29. fbo->Finish();
  30. fbo->Bind();
  31. model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
  32. fbo->Unbind();
  33. }
  34. void Draw()
  35. {
  36. glClearColor(0.0f,0.0f,0.0f,1.0f);
  37. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  38. fsq->mShader->SetTexture("U_Texture", fbo->GetBuffer("color"));
  39. fsq->Draw();
  40. }