init_render_to_texture.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  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. // glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
  23. // if(!depth_texture)
  24. // {
  25. // glBindRenderbuffer(GL_RENDERBUFFER, d_id);
  26. // }
  27. // //
  28. // // draw scene ...
  29. // //
  30. // // clean up
  31. // glBindFramebuffer(GL_FRAMEBUFFER,0);
  32. // if(!depth_texture)
  33. // {
  34. // glBindRenderbuffer(GL_RENDERBUFFER, 0);
  35. // }
  36. // // Later ...
  37. // glActiveTexture(GL_TEXTURE0+0);
  38. // glBindTexture(GL_TEXTURE_2D,tex_id);
  39. // if(depth_texture)
  40. // {
  41. // glActiveTexture(GL_TEXTURE0+1);
  42. // glBindTexture(GL_TEXTURE_2D,d_id);
  43. // }
  44. // // draw textures
  45. //
  46. //
  47. //
  48. // Inputs:
  49. // width image width
  50. // height image height
  51. // depth_texture whether to create a texture for depth or to create a
  52. // render buffer for depth
  53. // Outputs:
  54. // tex_id id of the texture
  55. // fbo_id id of the frame buffer object
  56. // d_id id of the depth texture or frame buffer object
  57. //
  58. IGL_INLINE void init_render_to_texture(
  59. const size_t width,
  60. const size_t height,
  61. const bool depth_texture,
  62. GLuint & tex_id,
  63. GLuint & fbo_id,
  64. GLuint & d_id);
  65. // 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