25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

92 satır
2.1 KiB

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