   [SOLVED] FBO with glReadPixel
  Decided to put this to a new post, kinda different issue:You guys got any samples or input on how to use the FBO's with glReadpixel?I've created my FBO:glGenFramebuffers(1, &selectionFbID_);Created a depth buffer, and a color buffer: (Or that's what I Think I'm doing, the tutorials regarding this are awfully vague)glGenRenderbuffers(1, &selectionDbID_);glGenRenderbuffers(1, &selectionCbID_);Initialized those two buffers, and bound them to the fbo, afaikglBindRenderbuffer(GL_RENDERBUFFER, selectionDbID_);glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, rendererSettings_->screenWidth, rendererSettings_->screenHeight);glBindRenderbuffer(GL_RENDERBUFFER, selectionCbID_);glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, rendererSettings_->screenWidth, rendererSettings_->screenHeight);glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, selectionCbID_);glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, selectionDbID_);Am I missing something crucial?After this, glCheckFramebufferStatus and glGetError show's it's supposedly a-ok.The above code is in my renderer class' constructor, now when I do render my selection quads, I have this code in a member function of the renderer class:// <---- Function start ---->glBindFramebuffer(GL_FRAMEBUFFER, selectionFbID_);glPushAttrib(GL_VIEWPORT_BIT);glViewport(0, 0, rendererSettings_->screenWidth, rendererSettings_->screenHeight);// Huge number of gl-disables herefor (...) {  glBegin();  // Quad rendering code that does work  glEnd();}// Then after rendering I wanna read from my FBO:glReadPixels(x, viewport[3] - y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);// Check for color matches here// And finallyglPopAttrib();glBindFramebuffer(GL_FRAMEBUFFER, 0);// <---- Function end---->Is there something I haven't taken into account for this to not be working?I'm one hundred percent sure the rendering code works fine, because my selection worked fine before trying to add the FBO-rendering to it...I'm guessing glReadPixels is reading the wrong place, or that my FBO is incomplete, any input regarding this?[Edited by - Shinpou on May 9, 2010 12:55:02 PM]
  Did you remember to glClear the FBO?Also, you probably want GL_RGBA8 instead of GL_RGBA4.   ;  Yeah, I did haveglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);Right before the glPopAttrib() call,Also, I changed the color format, but still it doesn't seem to be working.I'm just gonna post the whole rendering code here with all the redundant stuff that's in it:if (SelectionBuffer.size() > 0) {glBindFramebuffer(GL_FRAMEBUFFER, selectionFbID_);glPushAttrib(GL_VIEWPORT_BIT);glViewport(0, 0, rendererSettings_->screenWidth, rendererSettings_->screenHeight);// Disable everything that might change the end-product color of a rendered quadCurrentAssetUnderMouse = NULL;glDisable(GL_TEXTURE_2D);glDisable (GL_BLEND); glDisable (GL_DITHER);glDisable (GL_FOG); glDisable (GL_LIGHTING);glDisable (GL_TEXTURE_1D); glDisable (GL_TEXTURE_2D);glDisable (GL_TEXTURE_3D); glShadeModel (GL_FLAT);glPushMatrix();for (unsigned int i=0; i < SelectionBuffer.size(); i++) {AssetMetaData * CurrItem = SelectionBuffer;glMatrixMode( GL_MODELVIEW );// Load up the position matrix of the objectglLoadIdentity();ActiveCamera->Update();// Move object to it's positionglTranslatef(CurrItem->Position.x, CurrItem->Position.y, (GLfloat)-CurrItem->Depth);// Rotate object to it's orientationglRotatef(CurrItem->Orientation, 0.0f, 0.0f, 1.0f);glColor3ub(CurrItem->gColorID[0],CurrItem->gColorID[1],CurrItem->gColorID[2]);glBegin( GL_QUADS );// Top-left vertex (corner)glVertex3f( -CurrItem->Center.x, CurrItem->Size.y - CurrItem->Center.y, 0 );// Bottom-left vertex (corner)glVertex3f(  CurrItem->Size.x - CurrItem->Center.x, CurrItem->Size.y - CurrItem->Center.y, 0 );// Bottom-right vertex (corner)glVertex3f( CurrItem->Size.x - CurrItem->Center.x, -CurrItem->Center.y, 0 );// Top-right vertex (corner)glVertex3f( -CurrItem->Center.x, -CurrItem->Center.y, 0);glEnd();}unsigned char pixel[3];float x = X::GetSingleton().EngineState->GetPreDef(MouseCoordinateX);float y = X::GetSingleton().EngineState->GetPreDef(MouseCoordinateY);glReadPixels(x, rendererSettings_->screenWidth - y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);std::stringstream temp;temp << "R: " << (int)pixel[0];temp << " G: " << (int)pixel[1];temp << " B: " << (int)pixel[2];temp << " X: " << x;temp << " Y: " << y;DrawText(temp.str(),0,90,0.3);// now our picked screen pixel color is stored in pixel[3]// so we search through our object list looking for the object that was selectedfor (int i = 0; i < SelectionBuffer.size(); ++i) {if (SelectionBuffer->gColorID[0] == pixel[0] && SelectionBuffer->gColorID[1] == pixel[1] && SelectionBuffer->gColorID[2] == pixel[2]){CurrentAssetUnderMouse = SelectionBuffer->Asset;break;}}glPopMatrix();glEnable(GL_TEXTURE_2D);glEnable(GL_DITHER);glEnable(GL_BLEND);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPopAttrib();glBindFramebuffer(GL_FRAMEBUFFER, 0);}Am I using the FBO right?   ;  I think you forgot to bind your fbo before attaching the renderbuffers:glBindFramebuffer(GL_FRAMEBUFFER, selectionFbID_); // <-- this one before the followingglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, selectionCbID_);glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, selectionDbID_);Cheers.;  Oh yes!That was the issue exactly, thank you so much for that, I didn't realize it needed to be bound before that's being done. :)   