Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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