I’m drawing some 2D grids like 3DS Max or maya. The problem is that the viewport is not square and my code converts the square grids to the rectangle grids!
here’s my code:
//Draw to the upper left window
glViewport( 0, m_height / 2 , m_width / 2 , m_height / 2 );
glMatrixMode(GL_PROJECTION); // Sets the projection matrix.
glLoadIdentity(); // Reset the modelview matrix.
// calculate the aspect ratio of the window.
gluPerspective( 45.f, m_width / m_height , 0.1f, 10000.0f );
//or
//gluOrtho2D( -200. , 200. , -200. , 200. );
glMatrixMode(GL_MODELVIEW); // Sets the projection matrix.
glLoadIdentity(); // Reset the modelview matrix.
gluLookAt( 0.0, 0.0, 500.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f );
glColor3f( 0.7f, 0.7f, 0.7f );
glLineWidth( 1.0f );
glBegin( GL_LINES );
for( CInt index = -10; index <= 10; index++ )
{
glVertex3f( 0.0f + (CFloat)index * 20.0f, -200.0f, 0.0f );
glVertex3f( 0.0f + (CFloat)index * 20.0f, 200.0f, 0.0f );
glVertex3f( -200.0f ,(CFloat)index * 20.0f, 0.0f );
glVertex3f( 200.0f,(CFloat)index * 20.0f,0.0f );
}
glEnd();
What’s the problem?
-Ehsan-