Jump to content

  • Log In with Google      Sign In   
  • Create Account


gluUnProject failing?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 adam17   Members   -  Reputation: 227

Like
0Likes
Like

Posted 06 July 2007 - 04:40 AM

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?

Sponsor:

#2 niteice   Members   -  Reputation: 268

Like
0Likes
Like

Posted 06 July 2007 - 04:43 AM

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

#3 adam17   Members   -  Reputation: 227

Like
1Likes
Like

Posted 06 July 2007 - 05:05 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS