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

101 строка
2.3 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://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 USE_SDL && defined __APPLE__
  18. # include <SDL_main.h>
  19. #endif
  20. #if defined __native_client__
  21. # define main old_main
  22. #endif
  23. #if defined _WIN32
  24. # undef main /* FIXME: still needed? */
  25. # include <direct.h>
  26. #endif
  27. extern char const *lolfx_01_triangle;
  28. class Triangle : public WorldEntity
  29. {
  30. public:
  31. Triangle()
  32. {
  33. m_vertices << vec2( 0.0, 0.8);
  34. m_vertices << vec2(-0.8, -0.8);
  35. m_vertices << vec2( 0.8, -0.8);
  36. m_ready = false;
  37. }
  38. virtual void TickDraw(float seconds)
  39. {
  40. WorldEntity::TickDraw(seconds);
  41. if (!m_ready)
  42. {
  43. m_shader = Shader::Create(lolfx_01_triangle);
  44. m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0);
  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_vdecl->SetStream(m_vbo, m_coord);
  55. m_vdecl->Bind();
  56. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);
  57. m_vdecl->Unbind();
  58. }
  59. private:
  60. Array<vec2> m_vertices;
  61. Shader *m_shader;
  62. ShaderAttrib m_coord;
  63. VertexDeclaration *m_vdecl;
  64. VertexBuffer *m_vbo;
  65. bool m_ready;
  66. };
  67. int main(int argc, char **argv)
  68. {
  69. Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f);
  70. #if defined _MSC_VER && !defined _XBOX
  71. _chdir("..");
  72. #elif defined _WIN32 && !defined _XBOX
  73. _chdir("../..");
  74. #endif
  75. new DebugFps(5, 5);
  76. new Triangle();
  77. app.Run();
  78. return EXIT_SUCCESS;
  79. }