title: Using openGL's glBindFramebuffer seems to have no effect
body: <p>I am getting into FBOs (Framebuffer Objects) in openGL. Right now, I'm simply trying to render something to an FBO, then use the texture associated with it to render that image to the screen. I have been working on this problem for hours today and yesterday. I've tried copying as closely as I can two different examples, and yet I still have the same problem. I am absolutely stuck.</p>
  
  <p>It seems like what is happening is that the framebuffer object is not actually being binded. In the code, I have two sets of glClear() and glClearColor() commands: the first for drawing to the framebuffer, and the second for drawing to the screen. However, when I comment out the second set, the first set is clearly affecting the screen. If the FBO is binded, shouldn't it receive those commands, and <em>not</em> affect the actual output to the screen directly?</p>
  
  <p>To begin, I use glewInit(), and then I create an FBO, and then a Renderbuffer object and a texture to associate with it, and do all of the necessary steps to put it all together:</p>
  
  <pre><code>glewInit();
  
  int width=512,height=512;
  
  glGenFramebuffers(1, &amp;fbo);
  glGenRenderbuffers(1, &amp;rbo);
  glGenTextures(1, &amp;fboTex);
  
  glBindFramebuffer(GL_FRAMEBUFFER, fbo);
  
  glBindTexture(GL_TEXTURE_2D, fboTex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_INT, NULL);
  
  glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
  
  glBindRenderbuffer(GL_RENDERBUFFER, rbo);
  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
  
  GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  assert(status==GL_FRAMEBUFFER_COMPLETE);
  
  glBindTexture(GL_TEXTURE_2D,0);
  glBindFramebuffer(GL_FRAMEBUFFER,fbo);
  </code></pre>
  
  <p>Then, I draw to the framebuffer object.</p>
  
  <pre><code>glClearColor(0.5,0.5,0.5,1);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  
  glColor4f(1.0,0,0,1);
  glBegin(GL_QUADS);
  glVertex2f(100,100);
  glVertex2f(200,100);
  glVertex2f(200,250);
  glVertex2f(100,200);
  glEnd();
  </code></pre>
  
  <p>I then unbind each of the following three objects:</p>
  
  <pre><code>glBindFramebuffer(GL_FRAMEBUFFER,0);
  glBindRenderbuffer(GL_RENDERBUFFER,0);
  glBindTexture(GL_TEXTURE_2D,0);
  </code></pre>
  
  <p>Then I attempt to draw the texture to the window:</p>
  
  <pre><code>glEnable(GL_TEXTURE_2D);
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glBindTextureEXT(GL_TEXTURE_2D, fboTex);
  glBegin(GL_QUADS);
  glTexCoord2f(0,0);glVertex3f(-.5,-.5,0);
  glTexCoord2f(1,0);glVertex3f(.5,-.5,0);
  glTexCoord2f(1,1);glVertex3f(.5,.5,0);
  glTexCoord2f(0,1);glVertex3f(-.5,.5,0);
  glEnd();
  glDisable(GL_TEXTURE_2D);
  glFlush();
  </code></pre>
  
  <p>This has got to be either some really simple mistake or misunderstanding that somehow evaded eradication when I retyped all this <em>twice</em>, or a driver issue? My driver is supposed to be able to run version 3.2 of openGL...</p>
  
  <p>Any help on this frustrating issue would be great.</p>
  
  <p>EDIT: I found out what I was ultimately doing wrong. I didn't realize that glColor commands affected any drawing done, regardless of whether you have a framebuffer binded at the time or not. I needed to change the glColor <em>back</em> to (1,1,1) after drawing to the FBO, in order to render the FBO's texture later with all of its color.</p>