我在OpenGL中渲染時遇到問題。一切都顯示正常,直到我改變Z座標,它會被剪切/它不在視線內!那是怎麼回事?我是否設置我的透視投影矩陣是錯誤的?我很難...當我更換Z座標(OpenGL)時不顯示對象?
我的渲染代碼的相關位(mat4_
funcs是一個外部庫,和他們的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);
另請注意,我試過翻譯正面和負面的方向。
你從哪裏改變它? – Tim
檢查你的「近」/「遠」範圍。 –
@mihai maruseac:mat4_perspective(60.0f,800.0f/600.0f,0.1f,100.0f,NULL);設置接近0.1f,遠至100.0f – Shokwav