PDA

View Full Version : Picking objects problems



Zeka
12-25-2004, 03:59 AM
Hi!
There is a 3D scene with my units. User selects units by rectangling them. Then this rectangle goes to function:

unsigned *gapi_processSelection (const Rectf *rect, unsigned h, GDrawer *drawer)
{
unsigned selectBuf[BUFFSIZE];
int viewport[4];

glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(BUFFSIZE, selectBuf);
(void)glRenderMode(GL_SELECT);

glInitNames();
glPushName(0);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

double wc = rect->lr.x + (rect->ul.x - rect->lr.x)/2;
double hc = rect->lr.y + (rect->ul.y - rect->lr.y)/2;

gluPickMatrix( (double) wc,
(double) hc,
(double) (rect->ul.x - rect->lr.x),
(double) (rect->ul.y - rect->lr.y),
viewport );

gapi_setupProjectionSelection();
drawer->drawSelectionBB();

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
h = glRenderMode(GL_RENDER);

unsigned *selBuf = (unsigned *)malloc(sizeof(unsigned) * h);
for (int i = 0; i < h; i++) {
selBuf[i] = selectBuf[4 * i + 3];
}

return selBuf;
}But after this, when scene is drawing in normal mode, all glCallList() calls is much-much slower (about in 4 times). What I doing wrong?

Thank you!

Zeka
12-25-2004, 04:12 AM
drawSelectionBB() draws bounding boxes of my units. And if i delete this call here - all glCallList() runs as always! So, if I draw something between GL_SELECT and GL_RENDER - performanse is slower.