Hi thanks for your answer
Here is my code :
__Point __fastcall COglView::ScreenPointToViewPoint(__Point ptScreen)
{
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)ptScreen.GetLeft();
winY = (float)viewport[3] - (float)ptScreen.GetTop();
glReadPixels(ptScreen.GetLeft(), int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
return __Point((float)posX, (float)posY);
}
///////////////////////////////////////////////////////////////////////////////////
posZ return 1.0f, that should be ok
for my initialisation :
void COglView::ResizeGLScene()
{
// Reset The Main Viewport
glViewport(0, 0, (GLint)m_rcView.GetWidth(), (GLint)m_rcView.GetHeight());
// Select The Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset The Projection Matrix
glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
if (m_pOGL->GetProjectionMode() == OGL_Perspective)
{
gluPerspective(m_fMainFov, (GLfloat)m_rcView.GetWidth() / (GLfloat)m_rcView.GetHeight(), 0.1f, 1000.0f);
}
else if (m_pOGL->GetProjectionMode() == OGL_Orthogonal)
{
glOrtho(0, (GLfloat)m_rcView.GetWidth(), (GLfloat)m_rcView.GetHeight(), 0, 0.001, 1000000.0);
}
// Reselect The Modelview Matrix
glMatrixMode(GL_MODELVIEW);
// Reset The Modelview Matrix
glLoadIdentity();
}
///////////////////////////////////////////////////////////////////////////////////
ANd now for the drawing :
void COglView::DrawQuad()
{
__Point ptLeftTop(10.f, 10.f);
__Point ptRightTop(250.f, 10.f);
__Point ptRightBottom(250.f, 250.f);
__Point ptLeftBottom(10.f, 250.f);
__Point ptOglLeftTop = ScreenPointToViewPoint(ptLeftTop);
__Point ptOglRightTop = ScreenPointToViewPoint(ptRightTop);
__Point ptOglRightBottom = ScreenPointToViewPoint(ptRightBottom);
__Point ptOglLeftBottom = ScreenPointToViewPoint(ptLeftBottom);
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(ptOglLeftTop.GetLeft(), ptOglLeftTop.GetTop(), 0.0f);
glVertex3f(ptOglRightTop.GetLeft(), ptOglRightTop.GetTop(), 0.0f); // Top Right
glVertex3f(ptOglRightBottom.GetLeft(), ptOglRightBottom.GetTop(), 0.0f); // Bottom Right
glVertex3f(ptOglLeftBottom.GetLeft(), ptOglLeftBottom.GetTop(), 0.0f); // Bottom Left
glEnd();
}
I know using conversion function for each point is stupide, but it is juste for testing…
I you see a mistake in this please tell me
Thanks.