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.

102 lignes
2.4 KiB

  1. //
  2. // Lol Engine - Noise tutorial
  3. //
  4. // Copyright: (c) 2012 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://sam.zoy.org/projects/COPYING.WTFPL 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. #if defined _WIN32
  18. # include <direct.h>
  19. #endif
  20. extern char const *lolfx_03_noise;
  21. class NoiseDemo : public WorldEntity
  22. {
  23. public:
  24. NoiseDemo() :
  25. m_time(0.0),
  26. m_ready(false)
  27. {
  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_vertices << vec2(-1.0, 1.0);
  32. m_vertices << vec2( 1.0, -1.0);
  33. m_vertices << vec2( 1.0, 1.0);
  34. m_ready = false;
  35. }
  36. virtual void TickDraw(float seconds)
  37. {
  38. WorldEntity::TickDraw(seconds);
  39. m_time += seconds;
  40. if (!m_ready)
  41. {
  42. m_shader = Shader::Create(lolfx_03_noise);
  43. m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0);
  44. m_time_uni = m_shader->GetUniformLocation("u_Time");
  45. m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position));
  46. m_vbo = new VertexBuffer(m_vertices.Bytes());
  47. void *vertices = m_vbo->Lock(0, 0);
  48. memcpy(vertices, &m_vertices[0], m_vertices.Bytes());
  49. m_vbo->Unlock();
  50. m_ready = true;
  51. /* FIXME: this object never cleans up */
  52. }
  53. m_shader->Bind();
  54. m_shader->SetUniform(m_time_uni, m_time);
  55. m_vdecl->SetStream(m_vbo, m_coord);
  56. m_vdecl->Bind();
  57. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
  58. m_vdecl->Unbind();
  59. }
  60. private:
  61. Array<vec2> m_vertices;
  62. Shader *m_shader;
  63. ShaderAttrib m_coord;
  64. ShaderUniform m_time_uni;
  65. VertexDeclaration *m_vdecl;
  66. VertexBuffer *m_vbo;
  67. float m_time;
  68. bool m_ready;
  69. };
  70. int main(int argc, char **argv)
  71. {
  72. Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f);
  73. #if defined _MSC_VER && !defined _XBOX
  74. _chdir("..");
  75. #elif defined _WIN32 && !defined _XBOX
  76. _chdir("../..");
  77. #endif
  78. new NoiseDemo();
  79. app.Run();
  80. return EXIT_SUCCESS;
  81. }