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

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