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.

52 lines
1.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #include "scene.h"
  2. #include "ggl.h"
  3. #include "utils.h"
  4. #include "ground.h"
  5. glm::mat4 modelMatrix, viewMatrix, projectionMatrix;
  6. Ground ground;
  7. GLint textureLocation;
  8. Shader*shader;
  9. VertexBuffer*vertexbuffer;
  10. void Init() {
  11. /* ��ʼ��vbo��Ϊvbo��ֵ */
  12. vertexbuffer = new VertexBuffer;
  13. vertexbuffer->SetSize(3);
  14. vertexbuffer->SetPosition(0, -0.2f, -0.2f, 0.0f);
  15. vertexbuffer->SetTexcoord(0, 0.0f, 0.0f);
  16. vertexbuffer->SetColor(0, 1.0f, 1.0f, 1.0f);
  17. vertexbuffer->SetPosition(1, 0.2f, -0.2f, 0.0f);
  18. vertexbuffer->SetTexcoord(1, 1.0f, 0.0f);
  19. vertexbuffer->SetColor(1, 1.0f, 0.0f, 0.0f);
  20. vertexbuffer->SetPosition(2, 0.0f, 0.2f, 0.0f);
  21. vertexbuffer->SetTexcoord(2, 0.5f, 1.0f);
  22. vertexbuffer->SetColor(2, 0.0f, 1.0f, 0.0f);
  23. /* ��ʼ�� shader */
  24. shader = new Shader;
  25. shader->Init("Res/test.vs", "Res/test.fs");
  26. shader->SetTexture("U_Texture", "Res/test.bmp");
  27. shader->SetTexture("U_Texture2", "Res/test2.bmp");
  28. modelMatrix = glm::translate(0.0f, 0.0f, -0.6f);
  29. ground.Init();
  30. }
  31. void SetViewPortSize(float width, float height) {
  32. projectionMatrix = glm::perspective(60.0f, width / height, 0.1f, 1000.0f);
  33. }
  34. void Draw() {
  35. float frameTime = GetFrameTime();
  36. glClearColor(0.1f, 0.4f, 0.6f, 1.0f);
  37. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  38. ground.Draw(viewMatrix, projectionMatrix);
  39. vertexbuffer->Bind();
  40. shader->Bind(glm::value_ptr(modelMatrix), glm::value_ptr(viewMatrix), glm::value_ptr(projectionMatrix));
  41. glDrawArrays(GL_TRIANGLES, 0, 3);
  42. vertexbuffer->Unbind();
  43. }