No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

85 líneas
2.0 KiB

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