I'm following tutorial for picking in opengl. This is my function for picking,
int size = 25;
GLuint buffer[size];
glSelectBuffer(size, buffer);
glRenderMode(GL_SELECT);
glPushMatrix();
glLoadIdentity();
glGetIntegerv(GL_VIEWPORT, viewport);
gluPickMatrix(x, viewport[3] - y, 1000, 1000, viewport);
gluPerspective(60, ratio, 0.001, 1000);
glMatrixMode(GL_MODELVIEW);
glInitNames();
//give dummy name
glPushName(0);
draw_scene(scene_root, true);
glPopName();
//stop picking
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glFlush();
GLint hits = glRenderMode(GL_RENDER);
I'm using 1000,1000 for gluPickMatrix
just to get a hit
draw_scene boils down to
glLoadName(1);
mProgram.setUniformValue(mMvpMatrixLocation, getCameraMatrix() * transform);
glDrawArrays(GL_TRIANGLES, 40, 40 + v->sphereSize/3);
Get getCameraMatrix()
returns a QMatrix4x4
that represents my camera projection, and transform
is QMatrix4x4` that represents my model coordinates.
My shader.vert looks like this
in vec3 vert;
uniform mat4 mvpMatrix;
void main()
{
gl_Position = mvpMatrix * vec4(vert, 1.0);
}
Note mvpMatrix
is getCameraMatrix() * transform
I'm loading '1' temporally since I only have one object.
My issue is that it is not generating any hits despite the viewport being 1000x1000
edit:
The issue appears to that glRendmode(GL_SELECT)
does change the render mode. I created another question for this,