Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC OpenGL
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.
 
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 10-Apr-11 2:39am
Edited 29-May-12 22:44pm
(no name)158.8K
v2

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

  Print Answers RSS
0 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100