Hello all,
I'm trying to get my feet wet with using frame buffers. I've set up a frame buffer based off of a number of online tutorials, but the texture that I attached to it doesn't seem to be receiving the drawing. I like to debug these myself whenever possible, but I don't know how to check inside the frame buffer to see what's going on at runtime. Here is how I set up the frame buffer. Can anyone tell me if there is something missing?
Code :bool Setup_FrameBuffers() { // FramebufferName, renderedTexture and depthrenderbuffer are global GLuint pglGenFramebuffers(1, &FramebufferName); pglBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glGenTextures(1, &renderedTexture); // Texture glBindTexture(GL_TEXTURE_2D, renderedTexture); glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, 640, 385, 0,GL_RGB, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pglFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0); glBindTexture(GL_TEXTURE_2D, 0); // The depth buffer pglGenRenderbuffers(1, &depthrenderbuffer); pglBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer); pglRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 640, 385); pglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer); GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; pglDrawBuffers(1, DrawBuffers); if(pglCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; pglBindFramebuffer(GL_FRAMEBUFFER, 0); return true; }
The fragment shader I use is:
Code :#version 330 varying vec3 lighted_color; layout(location = 0) out vec4 output_color; void main (void) { output_color = vec4(lighted_color, 1.0); }
Basically I 1) Switch to the frame buffer, 2) render the scene, 3) switch back to the screen, and 4) draw the rendered texture. Nothing appears.
If I bypass the whole thing and render directly to the scene to the screen, (without this frame buffer business), it appears fine. If I switch out a pregenerated texture for step 4, it appears fine as well, but the rendered texture never appears. Suggestions?
PS: The "p" in front of some glFunctions is just a reminder to me that I had to pull them in from extensions. They are otherwise the same glFunctions.