Glut Mouse Coordinates

Is glutMouseFunc using a different coordinate system than my openGL?

For example, I have this texture drawn:


	glBegin(GL_QUADS);
	    glTexCoord2f(0,1); glVertex3f(0,-200,0);
	    glTexCoord2f(1,1); glVertex3f(100,-200,0);
	    glTexCoord2f(1,0); glVertex3f(100,-250,0);
	    glTexCoord2f(0,0); glVertex3f(0,-250,0);
	glEnd();

But when I’m trying to click on that texture w/ this function…


void mouse(int button, int state, int x, int y)
    {
	if (button==GLUT_LEFT && state==GLUT_DOWN)
	    {
		if (x>0 && x<100 && y>-250 && y<-250)
		    {
		    cout << "inside
";		    
		    }
		else
		    {
		    cout << "not inside
";
		    cout << "x: " << x << "
";
		    cout << "y: " << y << "
";
		    }
	    }
    }

My output is saying “not inside” with x=223 & y=314.

In “window” coordinate, the origin (0,0) is top left of the viewport.In OpenGL the origin is bottom left of the viewport. When you click glut give you the window coordinate. All you have to do is calculate this: y = height_of_viewport - y - 1.

Edit: Notice that you compare a screen coordinate (mouse click) with an object coordinate (your rectangle). This is fine if you use a perspective projection like this glOrtho(0,0,viewport_width,viewport_height). If not you need to call gluProject to map each corner of your rectangle in screen coordinate.

I can’t find any good resources (tutorials, examples) etc. w/ gluProject. Does anyone know of any?

What do you mean good resources? The manual page that TNT posted a link to explains everything very well.