Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. void genFBO(GLuint &FBO, GLuint &RBO, GLuint &textureColorbuffer, int width, int height)
  2. {
  3.     glGenFramebuffers(1, &FBO);
  4.     glBindFramebuffer(GL_FRAMEBUFFER, FBO);
  5.     textureColorbuffer = generateAttachmentTexture(false, false);
  6.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorbuffer, 0);
  7.     glGenRenderbuffers(1, &RBO);
  8.     glBindRenderbuffer(GL_RENDERBUFFER, RBO);
  9.     glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
  10.     glBindRenderbuffer(GL_RENDERBUFFER, 0);
  11.     glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RBO);
  12.     if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
  13.     {
  14.         cout << "FBO ERROR" << endl;
  15.     }
  16.     glBindFramebuffer(GL_FRAMEBUFFER, 0);
  17. }
  18.  
  19. GLuint generateAttachmentTexture(bool depth, bool stencil)
  20. {
  21.     int windowWidth, windowHeight;
  22.     windowWidth = 1360;
  23.     windowHeight = 765;
  24.  
  25.     // What enum to use?
  26.     GLenum attachment_type;
  27.     if (!depth && !stencil)
  28.         attachment_type = GL_RGB;
  29.     else if (depth && !stencil)
  30.         attachment_type = GL_DEPTH_COMPONENT;
  31.     else if (!depth && stencil)
  32.         attachment_type = GL_STENCIL_INDEX;
  33.  
  34.     //Generate texture ID and load texture data
  35.     GLuint textureID;
  36.     glGenTextures(1, &textureID);
  37.     glBindTexture(GL_TEXTURE_2D, textureID);
  38.     if (!depth && !stencil)
  39.         glTexImage2D(GL_TEXTURE_2D, 0, attachment_type, windowWidth, windowHeight, 0, attachment_type, GL_UNSIGNED_BYTE, NULL);
  40.     else // Using both a stencil and depth test, needs special format arguments
  41.         glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, windowWidth, windowHeight, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
  42.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  43.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  44.     glBindTexture(GL_TEXTURE_2D, 0);
  45.  
  46.     return textureID;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement