   Point Selection Problem - Revisit
  Hi all, I am struggling to develop an application in openGL that allows me to pick a particular point at a time , change its color and drag it to a new position with respect to other points.With my understanding and hard efforts I have been able to draw all points but not getting the desired results. Following is the relevant portion of my code concerning the above described function: //This function is responsible for dragging.void Drag(int iPos_X , int iPos_Y){ int i = iEle; int iIndex; //Var declarations for picking and selection. GLuint selectBuf[BUF_SIZE]; GLint ViewPort[FOUR] ; GLint iHits = 0; memset(selectBuf,0,BUF_SIZE); //clearif(bMiddleButton) //If middle mouse button is pressed.{    MarkPointOnScreen(iPos_X,iPos_Y, WINHEIGHT , WINWIDTH, NULL, pfTemp);   // Commented for temporarily.Using selection and picking for  selection..This works only for the last point. //pfArray = pfTemp[0];    //pfArray = pfTemp[1];    //pfArray = pfTemp[2];  //Modification required.Indexing of points neccessary. glGetIntegerv(GL_VIEWPORT,ViewPort); glSelectBuffer(BUF_SIZE,selectBuf);  //Entering SELECT mode. (void)glRenderMode(GL_SELECT); //Initialising name stack. glInitNames();    glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); //createpickmatrix.that is draw a viewing mode of size 1 * 1 pixel.gluPickMatrix((GLdouble)iPos_X , (GLdouble)(ViewPort[3] - iPos_Y) , 1.0 , 1.0 , ViewPort);   glOrtho(LEFT , RIGHT , BOTTOM, TOP ,MIN_LIMIT, MAX_LIMIT);    //Pick a point and turn its color as blue.drawPoint(GL_SELECT);//When mode is GL_SELECT then works as a Point picker.Aim is to return the index of the point picked.   glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush();   //Exiting from SELECT mode and entering NORMAL mode. iHits = glRenderMode(GL_RENDER);    processHits(iHits, selectBuf);}glutPostRedisplay();}//End of function</pre>And the code underneath is for drawPoint() that actually draws points and displays them.Moreover, when draggin is performed, th aim of the function is to continuously display the changing positions of the point being dragged.<pre>void drawPoint(GLenum mode){int i =0, j = 0, k = 0 ;    static iVar = 0;    int iIndex = 0; //if( mode != GL_SELECT)SHIFT_COORD_SIGN = SIGN(5.0 , 0.0);   glEnable(GL_DEPTH_TEST);   glEnable(GL_LINE_STIPPLE); // Set the material color to follow the current colorglMatrixMode(GL_MODELVIEW);   glLoadIdentity();  // …Deleting it gives weired effects.glPushMatrix();    glRotatef(fAngle_Y , 0.0 , 1.0 , 0.0); //Move leftglRotatef(fAngle_X , 1.0 , 0.0 , 0.0);  //Move aboveglRotatef(fAngle_Z , 0.0 , 0.0 , 1.0);  //Move above    glPointSize(POINT_SIZE);    while( j &lt; iNumOfClicks)    { //SHIIFT_COOR_SIGN is used &#111;n assumption that camera moves along Z axis.   //glVertex3f(SHIFT_COORD_SIGN * pfArray<span style="font-weight:bold;">, pfArray, pfArray );    if(bMiddleButton) // && mode == GL_SELECT)   { glColor3f(0.0 ,1.0 ,0.0);   //Section added w.ref to GameDev forum post. if (mode == GL_SELECT) glLoadName(j); //j is the point index here.glBegin(GL_POINTS);    glVertex3f(SHIFT_COORD_SIGN * pfArray<span style="font-weight:bold;">, pfArray, pfArray );    glEnd();// if(mode == GL_SELECT)// glPopName();    }  else  { glColor3f(1.0, 0.0, 1.0); glBegin(GL_POINTS);   glVertex3f(SHIFT_COORD_SIGN * pfArray<span style="font-weight:bold;"> * fZoom_X, pfArray * fZoom_Y, pfArray *fZoom_Z);   glEnd();  }    bDefault = TRUE;  //Reset Flag.   i += 3;   ++j;    }//End of While Loop glPopMatrix();i = 0; //Reset counter.j = 0; //Reset counter.   glutSwapBuffers(); }//End of function drawPoint.</pre>Problem is: When I press middle button of mouse, the color of each vertex turns green from original color purple.But when I drag a point, , I observe that number of Hits remains 0. With more efforts , I was able to drag the last drawn point &#111;nly by supplying to current mouse cursor position to glVertex3f function.I need a sceneario where , if I draw 4 points and I pick the 2nd point or 3rd and drag it, the point must move with respect to other points. ( i.e position of other points must not change and after dragging operation, all points should be displayed. Help is appreciated.
  Okay I have done a thing. In the drawPoint() stated above, I have indexed all points rendered on Left click. Now I want a way where When I pick a point, I get its index.Is it possible to do so?(i.e If I have points A,B and C with indices 0, 1 and 2 ; and I click on point B, I get index as 1. If I get index then problem is solvable.Any help on this or suggestions ?   ;  Do you have mismatching push/pops of names? I see you initialize using pushname(0). But when you draw a point, you use loadname(name), followed by popname(). Load name doesn't push a name, it writes over the current top of the name stack. A glGetError call would probably show you that you had (name)stack underflow.   ;Quote:Original post by Bob IIIDo you have mismatching push/pops of names? I see you initialize using pushname(0). But when you draw a point, you use loadname(name), followed by popname(). Load name doesn't push a name, it writes over the current top of the name stack. A glGetError call would probably show you that you had (name)stack underflow.Thanks Bob for your response. I believe in you. I was testing with snippet given in the redbook and did some modification.Can you point out what is wrong with the code given at the link : http://www.gamedev.net/community/forums/topic.asp?topic_id=396357  ( Above link is a link to my another post on this topic) . Thanks. I am checking about Push and Pop operations as pointed by you for the code in this post. Help Appreciated.   