Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

105 wiersze
2.4 KiB

  1. //
  2. // Lol Engine - Framebuffer Object 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 defined _WIN32
  18. # include <direct.h>
  19. #endif
  20. extern char const *lolfx_08_fbo;
  21. class FBO : public WorldEntity
  22. {
  23. public:
  24. FBO()
  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_08_fbo);
  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_fbo = new FrameBuffer(Video::GetSize());
  44. m_ready = true;
  45. /* FIXME: this object never cleans up */
  46. }
  47. m_fbo->Bind();
  48. m_shader->Bind();
  49. m_vdecl->SetStream(m_vbo, m_coord);
  50. m_vdecl->Bind();
  51. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);
  52. m_vdecl->Unbind();
  53. m_shader->Unbind();
  54. m_fbo->Unbind();
  55. m_shader->Bind();
  56. m_vdecl->SetStream(m_vbo, m_coord);
  57. m_vdecl->Bind();
  58. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);
  59. m_vdecl->Unbind();
  60. m_shader->Unbind();
  61. }
  62. private:
  63. Array<vec2> m_vertices;
  64. Shader *m_shader;
  65. ShaderAttrib m_coord;
  66. VertexDeclaration *m_vdecl;
  67. VertexBuffer *m_vbo;
  68. FrameBuffer *m_fbo;
  69. bool m_ready;
  70. };
  71. int main(int argc, char **argv)
  72. {
  73. Application app("Tutorial 08: Framebuffer Object", ivec2(640, 480), 60.0f);
  74. #if defined _MSC_VER && !defined _XBOX
  75. _chdir("..");
  76. #elif defined _WIN32 && !defined _XBOX
  77. _chdir("../..");
  78. #endif
  79. new DebugFps(5, 5);
  80. new FBO();
  81. app.Run();
  82. return EXIT_SUCCESS;
  83. }