Advertisement

Mouse Co-Ordinates

Started by March 16, 2004 09:59 AM
0 comments, last by Ructions 20 years, 11 months ago
I have text on screen and i want the mouse pointer to be able to click on them. But how do you convert windows mouse co-ordinates to opengl co-ordinates. so that i can click on them. Is it effected if the window is windowed and no fullscreen how to implement this Thanks in advance Ructions
Use gluUnProject. for the z coord use gluUnProject with 0 and 1
and you will have a line. Test to see if this line is colliding with the text.

Here''s the code I use

Vectors3f MouseToOpenGL(int X,int Y,float Z)
{
// DO NOT call this between glBegin & glEnd
GLdouble TempX;
GLdouble TempY;
GLdouble TempZ;
GLint Viewport[4];
GLdouble ModelView[16];
GLdouble Projection[16];
glGetDoublev(GL_MODELVIEW_MATRIX,ModelView);
glGetDoublev(GL_PROJECTION_MATRIX,Projection);
glGetIntegerv(GL_VIEWPORT,Viewport);
gluUnProject((GLdouble)X,(GLdouble)Y,(GLdouble)Z,ModelView,Projection,Viewport,&TempX,&TempY,&TempZ);
Vectors3f TempV((float)TempX,(float)TempY,(float)TempZ);
return(TempV);
}

You can also calculate a 3D bounding box for the text to make it easier

This topic is closed to new replies.

Advertisement