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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. }