Skip to main content
GameDev.net gamedev.net
🔒 Locked

Opengl picking

Started by beebop Apr 7, 2004 at 3:38 AM 0 replies 950+ views
Original Post
beebop
beebop
I''ve got a problem with the openGl picking. When I do a glGetError(); after glLoadName or glPushName, I''ve got: GL_INVALID_OPERATION is generated if glLoadName is called between a call to glBegin and the corresponding call to glEnd. I don''t understand ?! Here my code called after a mouse event: // void myView:icking(int mouseX, int mouseY) { GLint viewport[4] ; GLuint selectBuf[32] ; GLint hits ; glGetIntegerv (GL_VIEWPORT, viewport); glSelectBuffer (512, selectBuf); (void) glRenderMode (GL_SELECT); glInitNames(); glPushName(0) ; glMatrixMode(GL_PROJECTION) ; glPushMatrix() ; glLoadIdentity() ; gluPickMatrix(mouseX, viewport[3] - mouseY, 5, 5, viewport); gluPerspective( 45.0, (GLfloat)_viewW/(GLfloat)_viewH, _camera.getDistance()*0.1f, _camera.getDistance()*20.0f ); glMatrixMode(GL_MODELVIEW); glF1CRDraw(GL_SELECT); hits = glRenderMode(GL_RENDER); processHits(hits, selectBuf); glMatrixMode(GL_PROJECTION) ; glPopMatrix(); glMatrixMode(GL_MODELVIEW); } // In the drawing function, I put my glPushName or glLoadName (not between glBegin or glEnd). When I treat number of hits, I always obtain 0 !! What could be the problem ?? Camera ? .... Thanks a lot
Crispy
Crispy
Simple - do not call glLoadName() between glBegin() and glEnd(). There''s only so many GL functions that can be called there (~15 if I remember correctly) and glLoadName() couldn''t logically be one of them since glBegin() and glEnd() actually define an object in OpenGL (and names can only be assigned to objects).

For instance, if you want each point you''re rendering to have a name, try:


for(int i = 0; i < n; i++)
{
glLoadName(...).
glBegin(GL_POINTS);
glVertex(...);
glEnd();
}


note: didn''t have a look at your code




TCP - Transmission by Carrier Pigeons

"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.