簡體   English   中英

OpenGL中的透視投影矩陣顯示為黑色

[英]Perspective Projection Matrix in OpenGL appears black

我正在嘗試使用Haskell和OpenGL實現透視投影轉換。

我的頂點設置如下:

  let vertices =
        [ -0.3,  0.3,  0, -- Front Top Left 0                         
           0.3,  0.3,  0, -- Front Top Right 1 
           0.3, -0.3,  0, -- Front Bottom Right 2             
          -0.3, -0.3,  0, -- Front Bottom Left  3 
           0.3, 0.3,   0, -- Back Top Left      4            
           0.3,   0,   0, -- Back Top Right     5               
           0.3,   0,   0, -- Back Bottom Right  6              
           0.3, 0.3,   0  -- Back Bottom Left   7  ]

而且,不使用任何轉換,或僅使用“視圖”轉換,一切都會按應有的方式顯示(灰色方塊)。

視圖轉換是

 view = [cos ty * cos tz,    cos tz * sin tx * sin ty - cos tx * sin tz,         cos tx * cos tz * sin ty + sin tx * sin tz,    -cx,
         cos ty * sin tz,    cos tx * cos tz + sin tx * sin ty * sin tz,    -1 * cos tz * sin tx + cos tx * sin ty * sin tz,    -cy,
         -1 * sin ty,        cos ty * sin tx,                                    cos tx * cos ty,                               -cz,
         0,                  0,                                                  0,      1]

其中(cx, cy, cz)是攝影機的位置,而(tx, ty, tz)是攝影機繞軸以弧度歐拉角旋轉的角度。


當我應用透視變換時出現問題

perspective = [scale,     0,                        0,                     0,
                   0, scale,                        0,                     0,
                   0,     0, -1 * (far + near) / diff,                    -1,
                   0,     0,   -2 * near * far / diff,                     0]

其中diff = far - nearscale = 1.0 / tan (fov / 2.0)fov = 0.785

我的遠近平面分別是10和0.01。

應用后,使用以下GLSL代碼,將不會顯示任何內容(即,只有黑屏)。

void main()
{
    Color = color;
    gl_Position = perspective * view * vec4(position, 1.0);
}

我嘗試從多個不同的角度和位置查看正方形,並且禁用了剔除功能。

我的透視投影矩陣或其應用有什么問題?

這是通過轉置視圖矩陣解決的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM