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

  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", "Res/diffuse.fs");
  15. model.SetPosition(0.0f, 0.0f, 0.0f);
  16. //���û���������
  17. model.SetAmbientMaterial(0.1f, 0.1f, 0.1f, 1.0f);
  18. model.mShader->SetVec4("U_AmbientLight", 0.1f, 0.1f, 0.1f, 1.0f);
  19. //���û���������
  20. model.mShader->SetVec4("U_LightPos", 0.0f, 1.0f, 0.0f, 0.0f);
  21. model.SetDiffuseMaterial(0.4f, 0.4f, 0.4f, 1.0f);
  22. model.mShader->SetVec4("U_DiffuseLight", 0.8f, 0.8f, 0.8f, 1.0f);
  23. //���ø߹�����
  24. model.SetSpecularMaterial(1.0f, 1.0f, 1.0f, 1.0f);
  25. model.mShader->SetVec4("U_SpecualrLight", 1.0f, 1.0f, 1.0f, 1.0f);
  26. viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
  27. fsq = new FullScreenQuad();
  28. fsq->Init();
  29. fsq->mShader->Init("Res/fullscreenquad.vs", "Res/fullscreenquad.fs");
  30. }
  31. void SetViewPortSize(float width, float height)
  32. {
  33. projectionMatrix = glm::perspective(50.0f, width/height, 0.1f, 1000.0f);
  34. fbo = new FrameBufferObject();
  35. fbo->AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, (int)width, (int)height);
  36. fbo->AttachDepthBuffer("depth", (int)width, (int)height);
  37. fbo->Finish();
  38. fbo->Bind();
  39. glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
  40. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  41. model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
  42. fbo->Unbind();
  43. }
  44. void Draw()
  45. {
  46. glClearColor(0.0f,0.0f,0.0f,1.0f);
  47. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  48. fsq->mShader->SetTexture("U_Texture", fbo->GetBuffer("color"));
  49. fsq->Draw();
  50. }