Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all, I found a problem of the rendering in opengl when using gluUnProject to convert some point positions from windows coordinates to the object coordinates in opengl.
Although the converted object coordinates seem right, sparks of the rendering of quad/triangle will occur when the modelview matrix is changed(eg. using arcball). Similarly, discontinuity of the rendering of a line by connecting the points will occur.
I tested this function in both MFC and GLUI, the same results are observed.
Could someone tell me where the problem is and how to solve it please?
Thanks!

ps, I attached the render function as follows, you can have a try on that by pasting it into your own rendering code, to see if the same problem exists.

VB
void RenderIcon()
{
	GLint    viewport[4]; 
	GLdouble modelview[16]; 
	GLdouble projection[16]; 

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

	glDisable(GL_LIGHTING);

	glColor3f (1,0,0);

	GLdouble  winX, winY, winZ; 
	GLdouble posX, posY, posZ; 
	GLdouble posX2, posY2, posZ2; 
	GLdouble posX3, posY3, posZ3; 
	GLdouble posX4, posY4, posZ4; 

	winX = 550; winY = 550;
	glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); 
	gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &posX, &posY, &posZ);

	winX = 500; winY = 550;
	glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); 
	gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &posX2, &posY2, &posZ2);

	winX = 500; winY = 500;
	glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); 
	gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &posX3, &posY3, &posZ3);

	winX = 550; winY = 500;
	glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); 
	gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &posX4, &posY4, &posZ4);


	glBegin(GL_QUADS);
	glVertex3f(posX,posY,posZ);
	glVertex3f(posX2,posY2,posZ2);
	glVertex3f(posX3,posY3,posZ3);
	glVertex3f(posX4,posY4,posZ4);
	glEnd();


	glEnable(GL_LIGHTING);
}
Posted
Updated 29-May-12 21:44pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900