小编PSU*_*PSU的帖子

在调整窗口大小时保留 2D 对象的纵横比

我有一个 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 * …
Run Code Online (Sandbox Code Playgroud)

opengl

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

opengl ×1