2012-03-13 55 views
0

那么问题是类同我以前的一个约glOrtho变种
glOrtho OpenGL es 2.0 variant how fix blank screen?
Opengl ES 2.0中的glFrustrum变体 - 如何修复空白屏幕?

三角下面是邻投影完美的画(而不是在矩形视三个等边三角形,而不投影它​​压扁三角形)

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; 
    } 

设置我的投影矩阵T ø邻位,其中ASPECT_RATIO = SCREEN_WIDTH/screen_heigth

ortho_matrix(-aspect_ratio, aspect_ratio, -1.0, 1.0, -1.0, 1.0, PROJECTION_MATRIX); 

任务是邻投影更改为立体,所以我写此
UPD功能:改变为COL-主要

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,但矩阵为ortho func是从相同的来源和工作正常。无论如何,我看到类似https://stackoverflow.com/a/5812983/1039175截锥体函数类似的平截头体矩阵。

所有我得到的是空白屏幕,视口和其他与绘制有关的东西设置正确。

回答

2

看起来您的矩阵索引是从glFrustum的文档页面转换而来的。上传之前是否转换矩阵? OpenGL的通常是指列向量的矩阵,所以如果你从glFrustum复制公式,指数应该是这样的:

[0] [4] [ 8] [12] 
[1] [5] [ 9] [13] 
[2] [6] [10] [14] 
[3] [7] [11] [15] 
+0

+1列主要矩阵:) – Erik 2012-03-13 21:53:20

+0

将仔细检查,谢谢 – Aristarhys 2012-03-14 16:41:49

2

我不得不承认,我懒得看你的代码,但是......假设你清楚颜色设置为白色,这可能是因为您没有设置视口:

确保你渲染之前至少一次调用此:

GLint viewport[4]; 
glGetIntegerv(GL_VIEWPORT, viewport); 
GLsizei width = viewport[2]; 
GLsizei height = viewport[3]; 
glViewport(0, 0, width, height); 

至于一些普遍性的建议:不要试图用(也许除非出于某种理论上的目的)重写矩阵代码推倒重来。如果你考虑切换到C++,这是值得检查glm库:http://glm.g-truc.net/

它已经取代了你正在尝试实现的那些矩阵函数,然后一些...我自己使用它,这是一个梦幻般的数学库工作因为它专门针对opengl-es 2.0和glsl。

+0

+1投票GLM – Tim 2012-03-13 21:32:47

+0

视口设置,当然我也知道的GLM的,你有点 - 学术目的,无论如何+ 1 – Aristarhys 2012-03-14 16:38:28