Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

94 lignes
2.2 KiB

  1. //
  2. // Lol Engine - Noise tutorial
  3. //
  4. // Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. #include "loldebug.h"
  15. using namespace std;
  16. using namespace lol;
  17. LOLFX_RESOURCE_DECLARE(03_noise);
  18. class NoiseDemo : public WorldEntity
  19. {
  20. public:
  21. NoiseDemo() :
  22. m_time(0.0),
  23. m_ready(false)
  24. {
  25. m_vertices << vec2(-1.0, 1.0);
  26. m_vertices << vec2(-1.0, -1.0);
  27. m_vertices << vec2( 1.0, -1.0);
  28. m_vertices << vec2(-1.0, 1.0);
  29. m_vertices << vec2( 1.0, -1.0);
  30. m_vertices << vec2( 1.0, 1.0);
  31. m_ready = false;
  32. }
  33. virtual void TickDraw(float seconds)
  34. {
  35. WorldEntity::TickDraw(seconds);
  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. }