hi friends ,
iam doing a 3d cad program for my final project. i did almost completed it but stuck with the selection of objects . iam using a different func than rendering func to render into selection buffer but iam getting 0 hits always . i debugged it but no use!
here is the code that iam using for selection :
case SELECT:
if(SelectionClick && MOUSE[0].VALID)
{
BOOL bResult = wglMakeCurrent(pDC->m_hDC,myGL.m_hrc);
if (!bResult) return ;
int BUFFER_LENGTH=64;
int i=pDoc->scene.CurrentViewPort;
GLuint selectBuff[64]; // Space for selection buffer
GLint hits=0, viewport[4]; // Hit counter and viewport storeage
// Setup selection buffer
viewport[0]=pDoc->scene.viewport[pDoc->scene.CurrentViewPort].x;
viewport[1]=pDoc->scene.viewport[pDoc->scene.CurrentViewPort].y;
viewport[2]=pDoc->scene.viewport[pDoc->scene.CurrentViewPort].width;
viewport[3]=pDoc->scene.viewport[pDoc->scene.CurrentViewPort].height;
int curx,cury; //mouse start coordinates in openGL coordinate system
int mx1,my1; // starting mouse coordinates relative to view port
int cx1,cy1; // currernt mouse coordinates local to current view port
curx=MOUSE[0].X;
cury=myGL.height-MOUSE[0].Y;
mx1=curx-pDoc->scene.viewport[pDoc->scene.CurrentViewPort].x;
my1=cury-pDoc->scene.viewport[pDoc->scene.CurrentViewPort].y;
glViewport(pDoc->scene.viewport[i].x,pDoc->scene.viewport[i].y, pDoc->scene.viewport[i].width, pDoc->scene.viewport[i].height);
//glScissor(pDoc->scene.viewport[i].x,pDoc->scene.viewport[i].y, pDoc->scene.viewport[i].width, pDoc->scene.viewport[i].height);
//glEnable(GL_SCISSOR_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glSelectBuffer(BUFFER_LENGTH, selectBuff);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRenderMode(GL_SELECT);
gluPickMatrix(curx,cury, 20,20, viewport);
//glOrtho(0.0,myGL.width/2,0.0,myGL.height/2,1.0, 1000.0);
glInitNames();
glPushName(0);
myGL.DrawFrame(pDC,pDoc,myGL.m_hrc);
glFlush();
hits = glRenderMode(GL_RENDER);
// If a single hit occured, display the info.
//pDoc->scene.CurrentSelection=selectBuff[3];
for(int k=1;k<=hits;k++)
{ if(hits>1)
if (pDoc->scene.CurrentSelection!=selectBuff[((k-1)*4)+3])
pDoc->scene.CurrentSelection=selectBuff[((k-1)*4)+3];
else
pDoc->scene.CurrentSelection=selectBuff[((k-1)*4)+3];
}
TRACE1("selected=%d",pDoc->scene.CurrentSelection);
/// SwapBuffers(pDC->m_hDC);
wglMakeCurrent(NULL, NULL);
SelectionClick=false;
MOUSE[0].VALID=false;
//MOUSE[0].VALID=false;
}