View Full Version : Getting bits from fbo generated texture?

05-16-2010, 12:02 PM

I'm trying to get my mouse picking back in based on coloring. What I do is that I generate a new texture that I bind to an fbo on color attachment 1, and then write colors to the texels there. Back on the C++ side, my plan is to use the mouse's position, do a lookup in the texture and find out what color the mouse hovers over.

void GenericManager::update(double dt)
siut::simd::Vec2f pickCoord = siut::simd::Vec2f(0.0f, 0.0f);
pickCoord = this->getState()->getMousePos();

if(pickCoord.x() < 0.001f &amp;&amp; pickCoord.y() < 0.001f)

GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

pickCoord[1] = viewport[3] - pickCoord[1]; //port to opengl coords

unsigned int dpp = 3; //rgb

int aux = dpp*((int)pickCoord.y()*pickingMapSize + (int)pickCoord.x());
float r = pickingTextureBits[aux+0];
float g = pickingTextureBits[aux+1];
float b = pickingTextureBits[aux+2];

How do I get the pickingTextureBits from the opengl state though? I realized quickly that I had no idea how to get to that data. When loading a texture from disk, that's no problem, but is it possible to get a byte array (unsigned char) from a generated texture like I explained above?

05-16-2010, 12:46 PM
Hm, so I can either use glReadPixels from glRealBuffer(GL_COLOR_ATTACHMENT1), or do a full glGetTexImage?

I guess I only need to do the first approach in that case, and I guess I'll also have to perform the picking while the fbo is bound... got to test this :)

05-16-2010, 12:57 PM
Ok, that worked :P