【发布时间】:2012-03-15 04:42:30
【问题描述】:
这个问题与我之前关于 glOrtho 变体的问题类似
glOrtho OpenGL es 2.0 variant how fix blank screen?
下面的三角形在正交投影上完美绘制(没有投影它是压扁的三角形,而不是矩形视口上的三个等边三角形)
GLfloat triangle_vertices[] =
{
-0.5, -0.25, 0.0,
0.5, -0.25, 0.0,
0.0, 0.559016994, 0.0
};
正交矩阵代码:
typedef float[16] matrix;
void ortho_matrix(float right, float left, float bottom, float top, float near, float far, matrix result)
{
// First Column
result[0] = 2.0 / (right - left);
result[1] = 0.0;
result[2] = 0.0;
result[3] = 0.0;
// Second Column
result[4] = 0.0;
result[5] = 2.0 / (top - bottom);
result[6] = 0.0;
result[7] = 0.0;
// Third Column
result[8] = 0.0;
result[9] = 0.0;
result[10] = -2.0 / (far - near);
result[11] = 0.0;
// Fourth Column
result[12] = -(right + left) / (right - left);
result[13] = -(top + bottom) / (top - bottom);
result[14] = -(far + near) / (far - near);
result[15] = 1;
}
将我的投影矩阵设置为正交,其中 aspect_ratio = screen_width/screen_heigth
ortho_matrix(-aspect_ratio, aspect_ratio, -1.0, 1.0, -1.0, 1.0, PROJECTION_MATRIX);
任务是将正射投影更改为透视,因此我为此编写函数
UPD:更改为 col-major
void frustum_matrix(float right, float left, float bottom, float top, float near, float far, matrix result)
{
// First Column
result[0] = 2 * near / (right - left);
result[1] = 0.0;
result[2] = 0.0;
result[3] = 0.0;
// Second Column
result[4] = 0.0;
result[5] = 2 * near / (top - bottom);
result[6] = 0.0;
result[7] = 0.0;
// Third Column
result[8] = (right + left) / (right - left);
result[9] = (top + bottom) / (top - bottom);
result[10] = -(far + near) / (far - near);
result[11] = -1;
// Fourth Column
result[12] = 0.0;
result[13] = 0.0;
result[14] = -(2 * far * near) / (far - near);
result[15] = 0.0;
}
将我的投影设置为平截头体矩阵,其中 aspect_ratio = screen_width/screen_heigth
frustum_matrix(-aspect_ratio, aspect_ratio, -1.0, 1.0, 0.1, 1.0, PROJECTION_MATRIX);
好吧,我在 glFrustrum 页面http://www.opengl.org/sdk/docs/man/xhtml/glFrustum.xml 上查看了矩阵,但正交函数的矩阵来自相同的来源并且工作正常。无论如何,我在https://stackoverflow.com/a/5812983/1039175 frustum 函数等各个地方都看到了类似的截锥矩阵。
我得到的只是空白屏幕、视口和其他与绘图相关的东西都设置好了。
【问题讨论】:
标签: c opengl-es opengl-es-2.0