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.
 
 
 

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