unity, unity中GL.MultMatrix的一个超级bug

GL.MultMatrix与OpenGL固定管线的glMultMatrix函数行为并不一致,不是累乘,而是覆盖。

例如下面例子,本来预期是在(100,100)处画一个方块,而实际效果却是在(0,0)处画一个方块:

GL.PushMatrix();
  GL.LoadPixelMatrix();
  {
   //mult matrix
   Matrix4x4 mat1 = Matrix4x4.TRS(new Vector3(100,100,0),Quaternion.identity,Vector3.one);
   GL.MultMatrix (mat1);
   //mult matrix
   Matrix4x4 mat2 = Matrix4x4.identity;
   GL.MultMatrix (mat2); 
   //draw quad
   {
    float m_left = -20;
    float m_top = -20;
    float m_right = 20;
    float m_bottom = 20;
    Vector2 LU = new Vector2 (m_left, m_top);
    Vector2 LD = new Vector2 (m_left, m_bottom);
    Vector2 RU = new Vector2 (m_right, m_top);
    Vector2 RD = new Vector2 (m_right, m_bottom);
    uiMat.getInstance ().m_dftUIMat.SetPass (0);
    GL.Begin (GL.QUADS);
    GL.Color (Color.red);
    GL.Vertex (new Vector3 (LU.x, LU.y, 0));
    GL.Vertex (new Vector3 (LD.x, LD.y, 0));
    GL.Vertex (new Vector3 (RD.x, RD.y, 0));
    GL.Vertex (new Vector3 (RU.x, RU.y, 0));
    GL.End ();
   }
  }
  GL.PopMatrix();

 

参考:http://answers.unity3d.com/answers/1115934/view.html

posted on 2015-12-22 11:58  wantnon  阅读(675)  评论(0编辑  收藏  举报

导航