Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Lol Engine — Noise tutorial
  3. //
  4. // Copyright © 2012—2015 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 <lol/engine.h>
  16. #include "loldebug.h"
  17. using namespace lol;
  18. LOLFX_RESOURCE_DECLARE(03_noise);
  19. class NoiseDemo : public WorldEntity
  20. {
  21. public:
  22. NoiseDemo()
  23. : m_vertices({ vec2(-1.0, 1.0),
  24. vec2(-1.0, -1.0),
  25. vec2( 1.0, -1.0),
  26. vec2(-1.0, 1.0),
  27. vec2( 1.0, -1.0),
  28. vec2( 1.0, 1.0), }),
  29. m_time(0.0),
  30. m_ready(false)
  31. {
  32. }
  33. virtual void TickDraw(float seconds, Scene &scene)
  34. {
  35. WorldEntity::TickDraw(seconds, scene);
  36. m_time += seconds;
  37. if (!m_ready)
  38. {
  39. m_shader = Shader::Create(LOLFX_RESOURCE_NAME(03_noise));
  40. m_coord = m_shader->GetAttribLocation(VertexUsage::Position, 0);
  41. m_time_uni = m_shader->GetUniformLocation("u_time");
  42. m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position));
  43. m_vbo = new VertexBuffer(m_vertices.bytes());
  44. void *vertices = m_vbo->Lock(0, 0);
  45. memcpy(vertices, &m_vertices[0], m_vertices.bytes());
  46. m_vbo->Unlock();
  47. m_ready = true;
  48. /* FIXME: this object never cleans up */
  49. }
  50. m_shader->Bind();
  51. m_shader->SetUniform(m_time_uni, m_time);
  52. m_vdecl->SetStream(m_vbo, m_coord);
  53. m_vdecl->Bind();
  54. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
  55. m_vdecl->Unbind();
  56. }
  57. private:
  58. array<vec2> m_vertices;
  59. Shader *m_shader;
  60. ShaderAttrib m_coord;
  61. ShaderUniform m_time_uni;
  62. VertexDeclaration *m_vdecl;
  63. VertexBuffer *m_vbo;
  64. float m_time;
  65. bool m_ready;
  66. };
  67. int main(int argc, char **argv)
  68. {
  69. System::Init(argc, argv);
  70. Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f);
  71. new NoiseDemo();
  72. app.Run();
  73. return EXIT_SUCCESS;
  74. }