Jump to content
  • Advertisement
Sign in to follow this  

gluUnProject troubles

This topic is 4231 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

Hi i can't get the right co-ordinates from my mouse co-ordinates into my world co-ordinates. please help, code is below. any further information i could provide which will help, be more than willing to reply with thanks for looking
lvector GetOGLPos(int x, int y)
	GLint viewport[4];
	GLdouble modelview[16];
	GLdouble projection[16];
	GLfloat winX, winY, winZ;
	GLdouble posX, posY, posZ;

	glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
	glGetDoublev( GL_PROJECTION_MATRIX, projection );
	glGetIntegerv( GL_VIEWPORT, viewport );

	winX = (float)x;
	winY = (float)viewport[3] - (float)y;
	glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

	gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

	printf("\nCo-ord: %e %e %e", posX, posY, posZ);
	return lvector(posX, posY, posZ);

the key callback function - im using glut by the way. requirement.
void keys(unsigned char key, int x, int y) 
	if((key == 'r') || (key == 'R'))  {  angle+=0.2f; }
	if((key == 't') || (key == 'T')) {  angle-=0.4f; }
	   /*if(textureM == FALSE) 
		   textureM = TRUE;
		   init();  //enable texture mapping. put textures on all objects
	   else {
		   textureM = FALSE;
		   dTL(); //disable texture mapping switch back to state without any textures
   if((key == 'm') || (key == 'M')) {
	   if(textureOn == true) { textureOn = false; }
	   else { textureOn = true; }
   if((key == 'l') || (key == 'L')) {
	   if(lightsOn == true) { 
		   lightsOn = false; 
	   else { 
		   lightsOn = true; 
   if((key == 'a') || (key == 'A')) {
	   lvector vector(GetOGLPos(x,y));
	   scene->addLight(vector.x, vector.y, vector.z);
   if((key == 's') || (key == 'S')) {

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!