David
02-11-2000, 04:59 AM
hi All,
Im having problems with object selection using the 'GL_SELECT' method, it works some of the time but sometimes selecting a blank area of the screen gets 'hits' which relate to a particular object, also sometimes clicking an object doesnt work.
Im using glPerspective projection with gluLookAt (i had real problems until I used gluLookAt), I specify these when drawing the objects and when using 'GL_SELECT'
Thanks
Are you using gluPickMatrix(...) or something similar to shrink your view volume around the mouse position?
David
02-11-2000, 06:33 AM
Yes, my area is 2x2 around the mouse pointer, just as an aside, is this 2x2 pixels?
Hmm... maybe you could post some example code?
David
02-12-2000, 02:16 AM
this is the mouse click code..
void mouseclick(int button, int state, int x1, int y1)
{
GLuint selectBuf[512];
GLint hits;
GLint viewport[4];
if (button != GLUT_LEFT_BUTTON | | state != GLUT_DOWN)
return;
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(512, selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// 2x2 picking region
gluPickMatrix((GLdouble) x1, (GLdouble) viewport[3]-y1, 5.0, 5.0, viewport);
gluPerspective(45,(GLfloat)800/(GLfloat)600,1,900);
gluLookAt(0,0,800,0,0,0,0,1,0);
env.DrawScene (GL_SELECT);
glPopMatrix();
glFlush();
hits=glRenderMode(GL_RENDER);
if (hits >0 )
env.Proces*hitss (hits,selectBuf);
env.MouseMove(button, state, x1, y1);
}
this is the process hits code.
environment::Proces****s (GLint hits,GLuint buffer[])
{
unsigned int i, j;
selected = NULL;
GLuint names, *ptr, ind;
brick *bptr;
ptr = (GLuint *) buffer;
names = *ptr;
bptr = start;
//selected = bptr;
ptr++;
ptr++;
ptr++;
//ptr++;
names = *ptr;
while(bptr != NULL)
{
ind = bptr->GetIndex ();
if (names != ind)
i=-1;
else
selected = bptr;
bptr = bptr->next ;
}
}
and this is the display code...
environment: :DrawScene (GLenum mode)
{
float *rgbv;
int scale,pos[3];
GLuint index;
glPushMatrix();
rgbv = start ->GetColour ();
scale = start ->GetSize ();
index = start ->GetIndex ();
start ->GetPosition (pos);
glTranslatef(pos[0]-100,pos[1],pos[2]);
glColor3fv(rgbv);
glScalef(scale, scale, scale);
if(mode == GL_SELECT)
glLoadName(1);
glCallList(index);
glPopMatrix();
current = start->next ;
glPushMatrix();
rgbv = current ->GetColour ();
scale = current ->GetSize ();
index = current ->GetIndex ();
current ->GetPosition (pos);
glTranslatef(pos[0],pos[1],pos[2]);
glColor3fv(rgbv);
glScalef(scale, scale, scale);
if(mode == GL_SELECT)
glLoadName(2);
glCallList(index );
glPopMatrix();
}
Hope you can help
[This message has been edited by David (edited 02-12-2000).]
David
02-12-2000, 04:29 AM
oh, Ive just found out why,
I needed to set to MODELVIEW mode before calling the GL_SELECT command, it now works, but I got the code from the red book... Strange...
Thanks for the help anyway!!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.