init_render_to_texture.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_OPENGL_INIT_RENDER_TO_TEXTURE_H
  9. #define IGL_OPENGL_INIT_RENDER_TO_TEXTURE_H
  10. #include "../igl_inline.h"
  11. #include "gl.h"
  12. #include <cstdlib>
  13. namespace igl
  14. {
  15. namespace opengl
  16. {
  17. /// Create a frame buffer that renders color to a RGBA texture a depth to a
  18. /// "render buffer".
  19. ///
  20. /// After calling this, you can use with something like:
  21. ///
  22. /// \code{cpp}
  23. /// glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
  24. /// if(!depth_texture)
  25. /// {
  26. /// glBindRenderbuffer(GL_RENDERBUFFER, d_id);
  27. /// }
  28. /// //
  29. /// // draw scene ...
  30. /// //
  31. /// // clean up
  32. /// glBindFramebuffer(GL_FRAMEBUFFER,0);
  33. /// if(!depth_texture)
  34. /// {
  35. /// glBindRenderbuffer(GL_RENDERBUFFER, 0);
  36. /// }
  37. /// // Later ...
  38. /// glActiveTexture(GL_TEXTURE0+0);
  39. /// glBindTexture(GL_TEXTURE_2D,tex_id);
  40. /// if(depth_texture)
  41. /// {
  42. /// glActiveTexture(GL_TEXTURE0+1);
  43. /// glBindTexture(GL_TEXTURE_2D,d_id);
  44. /// }
  45. /// // draw textures
  46. /// \endcode
  47. ///
  48. ///
  49. /// @param[in] width image width
  50. /// @param[in] height image height
  51. /// @param[in] depth_texture whether to create a texture for depth or to create a
  52. /// render buffer for depth
  53. /// @param[out] tex_id id of the texture
  54. /// @param[out] fbo_id id of the frame buffer object
  55. /// @param[out] d_id id of the depth texture or frame buffer object
  56. ///
  57. IGL_INLINE void init_render_to_texture(
  58. const size_t width,
  59. const size_t height,
  60. const bool depth_texture,
  61. GLuint & tex_id,
  62. GLuint & fbo_id,
  63. GLuint & d_id);
  64. /// \overload
  65. /// \brief Wrapper with depth_texture = false for legacy reasons
  66. IGL_INLINE void init_render_to_texture(
  67. const size_t width,
  68. const size_t height,
  69. GLuint & tex_id,
  70. GLuint & fbo_id,
  71. GLuint & dfbo_id);
  72. }
  73. }
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "init_render_to_texture.cpp"
  76. #endif
  77. #endif