简体   繁体   English

OpenGL中的透视投影矩阵显示为黑色

[英]Perspective Projection Matrix in OpenGL appears black

I am attempting to implement a perspective projection transformation using Haskell and OpenGL. 我正在尝试使用Haskell和OpenGL实现透视投影转换。

My vertices are set up as follows: 我的顶点设置如下:

  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  ]

and, using no transformation, or just the View transformation, everything appears as it should (a grey square). 而且,不使用任何转换,或仅使用“视图”转换,一切都会按应有的方式显示(灰色方块)。

The view transformation is 视图转换是

 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]

where (cx, cy, cz) are the camera's position and (tx, ty, tz) are the cameras rotation about the axis in radian Euler angles. 其中(cx, cy, cz)是摄影机的位置,而(tx, ty, tz)是摄影机绕轴以弧度欧拉角旋转的角度。


The problems occurs when I apply the perspective transformation 当我应用透视变换时出现问题

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

where diff = far - near and scale = 1.0 / tan (fov / 2.0) and fov = 0.785 . 其中diff = far - nearscale = 1.0 / tan (fov / 2.0)fov = 0.785

My far and near planes are 10 and 0.01, respectively. 我的远近平面分别是10和0.01。

Once applied, using the following GLSL code, nothing appears (ie. only a black screen). 应用后,使用以下GLSL代码,将不会显示任何内容(即,只有黑屏)。

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

I have tried viewing the square from multiple different angles and positions, and with culling disabled. 我尝试从多个不同的角度和位置查看正方形,并且禁用了剔除功能。

What is wrong with my perspective projection matrix or the application of it? 我的透视投影矩阵或其应用有什么问题?

这是通过转置视图矩阵解决的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM