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.

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