Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

01_triangle.cpp 1.9 KiB

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