Sign in to follow this  

gluUnProject failing?

This topic is 3848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im using the following code to find the 3d position of my cursor:
GLint view[4] = {0,0,SCREEN_WIDTH, SCREEN_HEIGHT};
	GLdouble model[16];
	GLdouble proj[16];
	GLdouble OGL[3] = {0};
	int win[3] = {0};

	glGetDoublev(GL_MODELVIEW, model);
	glGetDoublev(GL_PROJECTION, proj);
	glGetIntegerv(GL_VIEWPORT, view);

	POINT m;
	GetCursorPos(&m);
	ScreenToClient(hWnd, &m);

	win[0] = m.x; 
	win[1] = view[3]-m.y;
	win[2] = 0;
	//glReadPixels((int)win[0], (int)win[1], 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &win[2]);
	
	if(gluUnProject(win[0], win[1], win[2], model, proj, view, &OGL[0], &OGL[1], &OGL[2]) == GL_TRUE)
	{
		glPushMatrix();
		glLoadIdentity();
		glTranslatef(0,0,-20);
		glRasterPos2f(-25,10);
		glPrint("OGLCoords: %4.2f, %4.2f, %4.2f", OGL[0], OGL[1], OGL[2]);
		glPopMatrix();
	}
	if(gluUnProject(win[0], win[1], 1, model, proj, view, &OGL[0], &OGL[1], &OGL[2]) == GL_FALSE)
	{
		glPushMatrix();
		glLoadIdentity();
		glTranslatef(0,0,-20);
		glRasterPos2f(-25,10);
		glPrint("gluUnProject Failed");
		glPopMatrix();
	}

	glLoadIdentity();
	glTranslatef(0,0,-20);
	glRasterPos2f(-25,11);
	glPrint("Viewport: %i, %i, %i, %i", view[0], view[1], view[2], view[3]);
	
	glRasterPos2f(-25,9);
	glPrint("WinMouse:%d, %d", win[0], win[1]);
	glRasterPos2f(-25,8);
	glPrint("Mouse: %i, %i", m.x, m.y);

im running into the problem of gluUnProject failing. all it returns is GL_FALSE. ive been looking around and i cant find a list of reasons why it could fail. any ideas?

Share this post


Link to post
Share on other sites
The first thing I would do is look at the value of
glGetError()
to see if any errors occurred during the call.

Share this post


Link to post
Share on other sites
the error its giving me is GL_INVALID_ENUM. i dont see any enum values in gluUnProject.

EDIT: oh wow. i checked my glGet functions and i was using GL_MODELVIEW and GL_PROJECTION instead of GL_MODELVIEW_MATRIX and GL_PROJECTION_MATRIX. thanks for the help!

Share this post


Link to post
Share on other sites
Sign in to follow this