Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1.  
  2.         //Generate and bind a new framebuffer.
  3.         glGenFramebuffers(1, &fbo);
  4.         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
  5.  
  6.         //Generate and bind a new texture target. Then bind it to the frame buffer.
  7.         glGenTextures(1, &colorBuffer);
  8.         glBindTexture(GL_TEXTURE_2D, colorBuffer);
  9.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  10.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  11.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_NEAREST);
  12.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_NEAREST);
  13.         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  14.         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBuffer, 0);
  15.  
  16.         //Generate the space to store the depth and stencil buffers.
  17.         glGenRenderbuffers(1, &rbo);
  18.         glBindRenderbuffer(GL_RENDERBUFFER, rbo);
  19.         glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
  20.         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
  21.  
  22.         //Unbind the render buffer and texture buffer.
  23.         glBindTexture(GL_TEXTURE_2D, 0);
  24.         glBindRenderbuffer(GL_RENDERBUFFER, 0);
  25.  
  26.         //Make sure the buffer is correctly set up.
  27.         GLenum status;
  28.         if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE)
  29.         {
  30.             std::cout << "Frame buffer status: " << std::hex << status << std::dec << std::endl;
  31.             std::cout << "Buffer ID's: " << fbo << " " << rbo << " " << colorBuffer << std::endl;
  32.             std::cout << "Width and Height: " << width << " " << height << std::endl;
  33.             assert(0 && "Could not generate frame buffer!");
  34.         }
  35.  
  36.         glBindFramebuffer(GL_FRAMEBUFFER, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement