Hi,

You are missing a call to

glMatrixMode(GL_MODELVIEW);

before you redraw the objects in the GL_SELECT mode. Take a look here:

http://gpwiki.org/index.php/OpenGL:Tutorialsicking

You can also take a look at lighthouse3D website.

What I don't understand is the coordinates returned by gluUnProject. They make no sense. Where could I find that code that uses gluUnProject?

mirna


Quote Originally Posted by Bulletbeast View Post
On the topic of picking, I can't seem to get any hits with it. Here's my code (based on this and the pages that follow):

Code:
int DrawSelectionScene(GLvoid)
{ 
  glTranslatef(0.0f,0.0f,zoom-26.0f);

  glRotatef(tilt,0.1f,0.0f,0.0f);
  glRotatef(spin,0.0f,0.0f,0.1f);
  
  glTranslatef(-galaxies[selected_galaxy].x*travelled,-galaxies[selected_galaxy].y*travelled,-galaxies[selected_galaxy].z*travelled);
  
  glColor4f(0.5f,0.5f,0.5f,0.5f);
  
  glInitNames();
  glPushName(0);
  
  // A circle to represent the Supergalactic Plane
  
  glLoadName(PLANE);
  glBegin(GL_TRIANGLE_FAN);
    glVertex2f(0,0);
    for(int i=0;i<52;i++){
       double angle = i*2*M_PI/52;
       glVertex2f(cos(angle)*(PLANE_START_SIZE+PLANE_INC_SIZE*(PLANE_NUM_CIRCLES-1)),sin(angle)*(PLANE_START_SIZE+PLANE_INC_SIZE*(PLANE_NUM_CIRCLES-1)));
    }
    glVertex2f(cos(0)*(PLANE_START_SIZE+PLANE_INC_SIZE*(PLANE_NUM_CIRCLES-1)),sin(0)*(PLANE_START_SIZE+PLANE_INC_SIZE*(PLANE_NUM_CIRCLES-1)));
  glEnd();
  
  // And quads for the galaxies
  
  for (int i=0; i<num_galaxies; i++)
	{
    glLoadName(i);
    
    glTranslatef(galaxies[i].x,galaxies[i].y,galaxies[i].z);

    glRotatef(-spin,0.0f,0.0f,0.1f);
    glRotatef(-tilt,1.0f,0.0f,0.0f);

	  glBegin(GL_QUADS);
    glTexCoord2f(0.0f,0.0f); glVertex3f(-0.8f, 0.8f, 0.0f);
    glTexCoord2f(0.0f,1.0f); glVertex3f( 0.8f, 0.8f, 0.0f);
	    glTexCoord2f(1.0f,1.0f); glVertex3f( 0.8f,-0.8f, 0.0f);
		  glTexCoord2f(1.0f,0.0f); glVertex3f(-0.8f,-0.8f, 0.0f);
    glEnd();

	  glRotatef(tilt,1.0f,0.0f,0.0f);
	  glRotatef(spin,0.0f,0.0f,0.1f);

	  glTranslatef(-galaxies[i].x,-galaxies[i].y,-galaxies[i].z);
  }  
  return TRUE;
}

void ProcessSelection(int X, int Y)
{ 
  GLuint select[SELECT_BUFFER_LENGTH];
  GLint hits, viewport[4];

  glSelectBuffer(SELECT_BUFFER_LENGTH, select);
  glGetIntegerv(GL_VIEWPORT, viewport);

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glRenderMode(GL_SELECT);
  
  gluPickMatrix(X, Y, 2, 2, viewport);
  gluPerspective(45.0f,(GLfloat)window_width/(GLfloat)window_height,0.1f,100.0f);

  DrawSelectionScene();

  hits = glRenderMode(GL_RENDER);

  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);

  return;
}
Wherever I click, the variable hits always turns out to be -1. What have I copypasted wrong?