示例#1
0
void ON_GL( ON_Viewport& viewport,
            int port_left, int port_right,
            int port_bottom, int port_top
          )
{
  // Sets viewport's port to port_* values and adjusts frustum
  // so it's aspect matches the port's.
  ON_Xform projectionMatrix; // camera to clip transformation

  const int port_width  = abs(port_right - port_left);
  const int port_height = abs(port_top - port_bottom);
  if ( port_width == 0 || port_height == 0 )
    return;
  const double port_aspect = ((double)port_width)/((double)port_height);

  viewport.SetFrustumAspect( port_aspect );

  viewport.SetScreenPort( port_left, port_right, port_bottom, port_top,
                          0, 0xff );

  ON_BOOL32 bHaveCameraToClip = viewport.GetXform( 
                                       ON::camera_cs,  
                                       ON::clip_cs,
                                       projectionMatrix 
                                       );

  if ( bHaveCameraToClip ) {
    projectionMatrix.Transpose();
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixd( &projectionMatrix.m_xform[0][0] );
  }
}