在 OpenGL 中渲染时遇到问题。一切都显示得很好,直到我改变 Z 坐标,它被剪裁/看不见了!是这样吗?我是否设置了透视投影矩阵错误?我被难住了...
我的渲染代码的相关位(mat4_
函数是一个外部库,类似于他们的 GL 朋友)。
vec3_t eyevec = vec3_create(NULL);
eyevec[0] = 0.0f;
eyevec[1] = 0.0f;
eyevec[2] = 0.1f;
vec3_t centervec = vec3_create(NULL);
centervec[0] = 0.0f;
centervec[1] = 0.0f;
centervec[2] = 0.0f;
vec3_t upvec = vec3_create(NULL);
upvec[0] = 0.0f;
upvec[1] = 1.0f;
upvec[2] = 0.0f;
vec3_t transvec = vec3_create(NULL);
transvec[0] = 0.0f;
transvec[1] = 0.0f;
transvec[2] = -2.0f;
mat4_t perspective = mat4_perspective(60.0f, 800.0f / 600.0f, 0.1f, 100.0f, NULL);
mat4_lookAt(eyevec, centervec, upvec, perspective);
mat4_t modelview = mat4_identity(NULL);
//mat4_translate(modelview, transvec, modelview); objects vanish when doing this!
mat4_multiply(perspective, modelview, perspective);
const GLfloat verts[] = {
//verts
0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.0f, 0.0f, 1.0f,
//colors
1.0f, 0.3f, 0.4f, 0.5f,
0.5f, 0.1f, 0.4f, 0.3f,
0.0f, 1.0f, 0.5f, 0.6f,
0.0f, 1.0f, 0.5f, 0.6f,
//tex coords
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
};
const GLushort indices[] = {3, 0, 2, 0, 2, 1};
glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, NULL);
另请注意,我尝试过正反两方面的翻译。