PDA

View Full Version : opengl gluUnProject rendering problem(sparks)



kyewong
04-10-2011, 04:48 AM
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. I tested it in example5 provided directly in the GLUI package, and the quad will spark when using arcball to rotate the objects.

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);
}

kyewong
04-11-2011, 07:22 AM
Still no one has any idea about this problem please?