PDA

View Full Version : problem with gluUnproject



abhijit
05-08-2005, 09:18 AM
Hi,
I am trying to draw text string wherever I click inside the window. To do that, I first obtain the x, y coordinates of the clicked point and use the gluUnProject with current modelview, projection and viewport setting to get the x, y and z. I set z to a fixed value say -1. I then use glRasterPos3f routine to place the label at the above x, y, z positions. However I found that there is a difference in x, y of the clicked point and the point where the label appears. I also tried to draw a point at the x, y, z and it differs from the actual clicked position. Could anyone plz explain what could be going wrong?

Thanks

-Abhijit

dorbie
05-09-2005, 01:33 AM
The unproject will unproject to eye space not world space. Your text will be transformed through the modelview matrix when drawn. To draw in eye space glLoadidentity on the modelview matrix.

Also watch what you use for z.

RigidBody
05-09-2005, 02:05 AM
if you only want to draw text it might be easier to use the GL_ARB_window_pos extension. with this extension you can use glWindowPos2iARB(x, y) to set the current raster position without having to care about projection/modelview/viewport matrices- the arguments x/y are window coordinates.

it is a bit more complicated since you have to use glXGetProcAddressARB (or the windows equivalent).


//
// usual includes etc.
//
typedef void ( *PFNGLWINDOWPOS2IAARBPROC) (GLint, GLint);
PFNGLWINDOWPOS2IAARBPROC glWindowPos2iARB = NULL;

//
// draw function
//
void draw() {

glWindowPos2iARB(100, 100); // set raster pos
glCallLists( ... ); // display text
}
//
// main
//
int main(int argc, char *argv[]) {

//
// init opengl; make context current
//

//
// get proc address
//
glWindowPos2iARB = (PFNGLWINDOWPOS2IAARBPROC) glXGetProcAddressARB((const GLubyte*) "glWindowPos2iARB");

if(glWindowPos2iARB == NULL) {
// error
}
}