glut picking clashes with drawing
I'm using GLUT for my windowing code, and I've created a picking function using gluPickMatrix that works pretty well, most of the time. My problem is that if the user waves their mouse over the screen before it displays, the mouseMove function gets called, which then calls my picking function. This works fine, but then the screen gets drawn once or more times, and then when mouseMove (and therefore the picking function) gets called after that, the program dies. I've tracked the problem down to something within the picking function, but I'm thinking that there's probably something inherently wrong with the code I've written.
Here is the picking function:
where anims is an array and drawBounding() just draws a rectangular prism.
Here is my drawing code for glut:
I can post more code if needed.
Any ideas?
Thank you,
-wyrmmage
Here is the picking function:
Code:
int clientDLL::pickClosest(anim* theAnims, int numOfAnims)
{
assert(windowHeight != 0);
assert(windowWidth != 0);
//numOfAnims starts at 1
glSelectBuffer(512,selectBuffer);
glRenderMode(GL_SELECT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glGetIntegerv(GL_VIEWPORT,viewport);
gluPickMatrix(mouseX,viewport[3]-mouseY,5,5,viewport);
gluPerspective(45.0f,(GLfloat)windowWidth/(GLfloat)windowHeight,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glInitNames(); // Initializes The Name Stack
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.0f);
for(int i=0; i<numOfAnims; i++)
{
glPushName(i);
theAnims[i].drawBounding();
//theAnims[i]->drawBounding();
if(i != numOfAnims-1)
{
glPopName();
}
}
// restoring the original projection matrix
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glFlush();
//glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
int hits=glRenderMode(GL_RENDER); // Switch To Render Mode, Find Out How Many
if (hits != 0) // If There Were More Than 0 Hits
{
int choose = selectBuffer[3]; // Make Our Selection The First Object
int depth = selectBuffer[1]; // Store How Far Away It Is
for (int loop = 1; loop < hits; loop++) // Loop Through All The Detected Hits
{
// If This Object Is Closer To Us Than The One We Have Selected
if (selectBuffer[loop*4+1] < GLuint(depth))
{
choose = selectBuffer[loop*4+3]; // Select The Closer Object
depth = selectBuffer[loop*4+1]; // Store How Far Away It Is
}
}
cout << "clicked: " << choose << "\n";
return choose;
}
else
{
cout << "clicked nothing \n";
return -1;
}
}Here is my drawing code for glut:
Code:
void display(void)
{
cout << "\nentering display\n\n";
#if defined(__APPLE_CC__)
elapsedTime = elapsedTime + (AbsoluteToDuration(UpTime()) - AbsoluteToDuration(theTime));
theTime = UpTime();
#else
elapsedTime += (GetTickCount() - theTime);
theTime = GetTickCount();
#endif
numOfFrames++;
if(elapsedTime >= 1000)
{
cout << "FPS: " << numOfFrames << "\n";
numOfFrames = 0;
elapsedTime = 0;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
game->draw();
glutSwapBuffers();
}I can post more code if needed.
Any ideas?

Thank you,
-wyrmmage
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
"dies" is not helpful. What exactly happens?
Don't call glFlush, it's just a performance penalty for no benefit.
You might like glutGet(GLUT_ELAPSED_TIME) for cross-platform timing, too.
Don't call glFlush, it's just a performance penalty for no benefit.
You might like glutGet(GLUT_ELAPSED_TIME) for cross-platform timing, too.
hmmm....looks like it doesn't happen on the Mac, just Windows 
By 'dies' I mean it just crashes. I've tried to debug it, but the debugger is being incredibly unhelpful and giving me the error message: 'SIGSEGV, Segmentation fault. 0x693f730c in atioglxx!atiPPHSN () from C:\Windows\system32\atioglxx.dll
I'm no Windows wizard, but I'm guessing that its dying in opengl somewhere? Lost as to to where I should go from here, though
Anyway, sorry about the post since it's not really Mac related. I think I'll leave it alone for now and try to fix it eventually.
-wyrmmage

By 'dies' I mean it just crashes. I've tried to debug it, but the debugger is being incredibly unhelpful and giving me the error message: 'SIGSEGV, Segmentation fault. 0x693f730c in atioglxx!atiPPHSN () from C:\Windows\system32\atioglxx.dll
I'm no Windows wizard, but I'm guessing that its dying in opengl somewhere? Lost as to to where I should go from here, though

Anyway, sorry about the post since it's not really Mac related. I think I'll leave it alone for now and try to fix it eventually.
-wyrmmage
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| How do I do Color Picking? | dockode | 2 | 4,132 |
Sep 24, 2011 08:02 PM Last Post: dockode |
|
| Issues with picking | FFaqui | 0 | 1,899 |
Nov 21, 2009 04:37 PM Last Post: FFaqui |
|
| Opengl picking problem (zip file) | papillon68 | 1 | 3,749 |
Mar 1, 2009 08:49 PM Last Post: chronus |
|
| Picking and selection... | chalamov33 | 2 | 2,985 |
Mar 31, 2008 02:08 PM Last Post: wyrmmage |
|
| picking glOrtho vs gluPerspective | rhiannon | 0 | 3,086 |
Jun 6, 2005 02:20 PM Last Post: rhiannon |
|

