【发布时间】:2011-05-19 07:58:46
【问题描述】:
我有一个需要在窗口中显示二维矩形的 Windows (XP) 应用程序。矩形不得被剪裁(即必须始终完全位于视口内),并且必须在调整大小时保持其纵横比。目前,处理布局的方法会扭曲矩形的纵横比以匹配窗口。我希望矩形缩放到窗口并在窗口中居中(同样,没有剪裁)。目前的方法如下。 lWinDist 和 lMaxDepth 是要显示的矩形的宽度和高度(如果重要,以 48 英寸为单位):
void CRoRRecView::RedoLayout( long lWinDist, long lMaxDepth )
{
CDC* pDC = GetDC() ;
if ( pDC != NULL )
{
m_lWinDist = lWinDist;
GetClientRect( m_rectClient ) ;
int nClientWidth = m_rectClient.Width();
int nClientHeight = m_rectClient.Height();
glViewport( 0, 0, nClientWidth, nClientHeight );
glMatrixMode( GL_PROJECTION);
glLoadIdentity();
m_fWinXDist = (float) lWinDist ;
m_fWinYDist = lMaxDepth ;
m_fAspectRatio = m_fWinXDist / m_fWinYDist;
glOrtho(0.0, m_fWinXDist, 0.0, m_fWinYDist, -1, 1 ) ;
glRotatef(180.0, 0,1,0);
glTranslatef( (float)(-1 * lWinDist),0,0 ); // Translate across the x axis
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
ReleaseDC( pDC ) ;
}
}
【问题讨论】:
标签: opengl