Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

96 rindas
2.3 KiB

  1. //
  2. // Lol Engine — Noise tutorial
  3. //
  4. // Copyright © 2012—2019 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #if HAVE_CONFIG_H
  13. # include "config.h"
  14. #endif
  15. #include <memory>
  16. #include <lol/engine.h>
  17. #include "loldebug.h"
  18. using namespace lol;
  19. LOLFX_RESOURCE_DECLARE(03_noise);
  20. class NoiseDemo : public WorldEntity
  21. {
  22. public:
  23. virtual bool init_draw() override
  24. {
  25. array<vec2> vertices
  26. {
  27. vec2(-1.0, 1.0),
  28. vec2(-1.0, -1.0),
  29. vec2( 1.0, -1.0),
  30. vec2(-1.0, 1.0),
  31. vec2( 1.0, -1.0),
  32. vec2( 1.0, 1.0),
  33. };
  34. m_shader = Shader::Create(LOLFX_RESOURCE_NAME(03_noise));
  35. m_coord = m_shader->GetAttribLocation(VertexUsage::Position, 0);
  36. m_time_uni = m_shader->GetUniformLocation("u_time");
  37. m_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position));
  38. m_vbo = std::make_shared<VertexBuffer>(vertices.bytes());
  39. m_vbo->set_data(vertices.data(), vertices.bytes());
  40. return true;
  41. }
  42. virtual void tick_draw(float seconds, Scene &scene) override
  43. {
  44. WorldEntity::tick_draw(seconds, scene);
  45. m_time += seconds;
  46. m_shader->Bind();
  47. m_shader->SetUniform(m_time_uni, m_time);
  48. m_vdecl->Bind();
  49. m_vdecl->SetStream(m_vbo, m_coord);
  50. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
  51. m_vdecl->Unbind();
  52. }
  53. virtual bool release_draw() override
  54. {
  55. m_shader.reset();
  56. m_vdecl.reset();
  57. m_vbo.reset();
  58. return true;
  59. }
  60. private:
  61. std::shared_ptr<Shader> m_shader;
  62. ShaderAttrib m_coord;
  63. ShaderUniform m_time_uni;
  64. std::shared_ptr<VertexDeclaration> m_vdecl;
  65. std::shared_ptr<VertexBuffer> m_vbo;
  66. float m_time = 0.0;
  67. };
  68. int main(int argc, char **argv)
  69. {
  70. sys::init(argc, argv);
  71. Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f);
  72. new NoiseDemo();
  73. app.Run();
  74. return EXIT_SUCCESS;
  75. }