setPerspective OpenGL之后缺少对象 [英] Missing object after setPerspective OpenGLes
问题描述
我开始用OpenGL学习3D编程,所以我就是这个新手:p。
我想问一些东西,我试图在我的物体上设置透视(矩形面,6个顶点)。
但是,在setPerspective之后我再也看不到我的物体了。
Hi,
I'm starting to study 3D programming with OpenGLes, so I'm total newbie on this :p.
I wanna ask something, I tried to set Perspective on my object (rectangle face, 6 vertices).
But, after setPerspective I couldn't see my object anymore.
int init(....)
{
...
projMatrix.SetPerspective(45.0f, 0.75f, 0.001f, 100.0f);
...
}
void draw (...)
{
...
wvpMatrix = worldMatrix * viewMatrix * projMatrix;
glUniformMatrix4fv(myShaders.wvpMatrixLocation, 1, GL_FALSE, (const GLfloat*)wvpMatrix.m);
//end
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D,0);
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
}
这是setPerspective:
this is setPerspective :
Matrix & Matrix::SetPerspective(GLfloat fovY, GLfloat aspect, GLfloat nearPlane, GLfloat farPlane)
{
GLfloat height = 2.0f * nearPlane * tanf(fovY * 0.5f);
GLfloat width = height * aspect;
GLfloat n2 = 2.0f * nearPlane;
GLfloat rcpnmf = 1.f / (nearPlane - farPlane);
m[0][0] = n2 / width;
m[1][0] = 0;
m[2][0] = 0;
m[3][0] = 0;
m[0][1] = 0;
m[1][1] = n2 / height;
m[2][1] = 0;
m[3][1] = 0;
m[0][2] = 0;
m[1][2] = 0;
m[2][2] = (farPlane + nearPlane) * rcpnmf;
m[3][2] = farPlane * rcpnmf * n2;
m[0][3] = 0;
m[1][3] = 0;
m[2][3] = -1.f;
m[3][3] = 0;
return *this;
}
任何人都可以解雇我吗?
谢谢
anyone can hep me?
thanks
推荐答案
您可以调用
Matrix::GetPerspective
来获取当前值,然后稍微更改每个值以查看效果并找出解决方法这是因为你正在改变这些改变的程度,导致你的对象看不见。
这假设当然有这样的方法。
to get the current values and then change each one slightly to see the effect and work out what it is that you are changing and the extent of those changes that causes your object to be unseen that way.
this assumes there is such a method of course.
试试这个:
Try this:
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D,0);
glDrawArrays(GL_TRIANGLES, 0, 6);
在调用任何绘图函数之前你有绑定缓冲区。
-Saurabh
You have you bind buffers before calling any draw functions.
-Saurabh
>
这篇关于setPerspective OpenGL之后缺少对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!