PDA

View Full Version : object picking - win32 project using opengl



AndreasAustria
05-19-2010, 03:10 AM
hi all. i am writing a visualization program for 3D files like .stl files. until now everything is fine. the visualization, rotation, zoom of the 3D structure works perfect. but now i want to pick single triangles or groups of triangles. but nothing gets on the buffer in selection mode. and i don't really understand where my fault is.
my first step is
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glColor4f(1.0f,1.0f,1.0f,0.3f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glSelectBuffer(PICK_BUF_SZ, PickBuffer);
when gl gets initiated.
i am in render mode until a key gets pressed. now what do i do when the key is pressed:
glRenderMode (GL_SELECT);
pickTriangles (GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), LOWORD(lParam), HIWORD(lParam));
and in pickTriangles:
void pickTriangles (int x, int y, int w, int h)
{
if (RenderMode == GL_SELECT)
{
viewport[0] = x;
viewport[1] = y;
viewport[2] = w;
viewport[3] = h;
gluPickMatrix((double)x, (double)(h-y), PICK_TOL, PICK_TOL, viewport);
}
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,1.0f,600.0f);
if (RenderMode == GL_SELECT)
{
glInitNames();
glPushName(0xffffffff);
}
DrawGLScene();
hits = glRenderMode(GL_RENDER);
}
and in DrawGLScene:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(xmove,-ymove,-50.0f+zoom);
glRotatef(rotation,0.0f,1.0f,0.0f);
glRotatef(rot2,1.0f,0.0f,0.0f);
if (points == 0)
{
while (through < num_of_facets)
{
glLoadName(through);
glBegin(display);
glColor3f(0.9f,0.9f,0.9f);
glNormal3f(matrix[through][0], matrix[through][1], matrix[through][2]);
glVertex3f(matrix[through][3], matrix[through][4], matrix[through][5]);
glColor3f(0.9f,0.9f,0.9f);
glVertex3f(matrix[through][6], matrix[through][7], matrix[through][8]);
glColor3f(0.9f,0.9f,0.9f);
glVertex3f(matrix[through][9], matrix[through][10], matrix[through][11]);
glEnd();
through++;
}
}
and after the drawing:
hits = glRenderMode(GL_RENDER);

nothing in the buffer, no hits. have i forgotten something. can you see a problem?
thanks a lot for answering!