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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Lol Engine - Triangle 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 HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <lol/engine.h>
  14. #include "loldebug.h"
  15. using namespace lol;
  16. LOLFX_RESOURCE_DECLARE(01_triangle);
  17. class Triangle : public WorldEntity
  18. {
  19. public:
  20. Triangle()
  21. : m_vertices({ vec2( 0.0, 0.8),
  22. vec2(-0.8, -0.8),
  23. vec2( 0.8, -0.8) }),
  24. m_ready(false)
  25. {
  26. }
  27. virtual void TickDraw(float seconds, Scene &scene)
  28. {
  29. WorldEntity::TickDraw(seconds, scene);
  30. if (!m_ready)
  31. {
  32. m_shader = Shader::Create(LOLFX_RESOURCE_NAME(01_triangle));
  33. m_coord = m_shader->GetAttribLocation(VertexUsage::Position, 0);
  34. m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position));
  35. m_vbo = new VertexBuffer(m_vertices.Bytes());
  36. void *vertices = m_vbo->Lock(0, 0);
  37. memcpy(vertices, &m_vertices[0], m_vertices.Bytes());
  38. m_vbo->Unlock();
  39. m_ready = true;
  40. /* FIXME: this object never cleans up */
  41. }
  42. m_shader->Bind();
  43. m_vdecl->SetStream(m_vbo, m_coord);
  44. m_vdecl->Bind();
  45. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 3);
  46. m_vdecl->Unbind();
  47. }
  48. private:
  49. array<vec2> m_vertices;
  50. Shader *m_shader;
  51. ShaderAttrib m_coord;
  52. VertexDeclaration *m_vdecl;
  53. VertexBuffer *m_vbo;
  54. bool m_ready;
  55. };
  56. int main(int argc, char **argv)
  57. {
  58. System::Init(argc, argv);
  59. Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f);
  60. new DebugFps(5, 5);
  61. new Triangle();
  62. app.Run();
  63. return EXIT_SUCCESS;
  64. }