The glutPassiveMotionFunc callback is called with the coordinates of the pointer whenever it is moved within the window. You will not get any callbacks if moved outside the window. But I'm not sure what your question really is.
I'm sorry that I can explain my problem well. Here is a short program that can demonstrate what I'm talking about.
You may run this program with the pointer outside the program window. And before you move you mouse into the program window, you can already see a black line which is the problem that confuses me.
#include<GL/glut.h>
GLint viewWidth = 400, viewHeight = 400;
int centerX = 200, centerY = 200;
int tempX, tempY;
void drawLine( int x, int y)
{
glBegin( GL_LINES);
glVertex2i( centerX, centerY);
glVertex2i( x, y);
glEnd();
}
void init()
{
glClearColor( 0.0, 0.0, 1.0, 1.0);
glMatrixMode( GL_PROJECTION);
gluOrtho2D( 0.0, 400.0, 0.0, 400.0);
}
void myDisplay()
{
glClear( GL_COLOR_BUFFER_BIT);
glColor3f( 0.0, 0.0, 0.0);
drawLine( tempX, tempY);
glutSwapBuffers();
}
void myMouseMove( int x, int y)
{
tempX = x;
tempY = viewHeight - y;
glutPostRedisplay();
}
void main( int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE| GLUT_RGB);
glutInitWindowPosition( 100, 100);
glutInitWindowSize( viewWidth, viewHeight);
glutCreateWindow( "problem demonstration");
init();
glutDisplayFunc( myDisplay);
glutPassiveMotionFunc( myMouseMove);
glutMainLoop();
}
Thank you for your reply!