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.

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