I found a way to convert my mouse coordinates to world coordinates that I can easily understand but now I need to know how to use it to check if the mouse is currently over any of my rendered objects.
Here is my mouse click code that converts the mouse coordinates to screen coordinates when the left mouse button is clicked.
code:
void mouseClick( int button, int state, int x, int y ){ //if any mouse button was pressed if (button == GLUT_LEFT && state == GLUT_DOWN) { GLint viewport[4]; //hold the viewport info GLdouble modelview[16]; //hold the modelview info GLdouble projection[16]; //hold the projection matrix info GLfloat winX, winY, winZ; //hold screen x,y,z coordinates GLdouble worldX, worldY, worldZ; //hold world x,y,z coordinates glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); //get the modelview info glGetDoublev( GL_PROJECTION_MATRIX, projection ); //get the projection matrix info glGetIntegerv( GL_VIEWPORT, viewport ); //get the viewport info winX = (float)x; winY = (float)viewport[3] - (float)y; //get the world coordinates from the screen coordinates gluUnProject( winX, winY, 0.0, modelview, projection, viewport, &worldX, &worldY, &worldZ); gluUnProject( winX, winY, 1.0, modelview, projection, viewport, &worldX, &worldY, &worldZ); } } I've tested it to make sure that the coordinates are converting successfully, and it works fine!!!
As for the near and far planes I did double check that their coordinates are the same as defined in my glorthro.