0
我想繪製一個簡單的立方體,圍繞y軸旋轉45度。我的繪製代碼如下所示:openGL ES如何獲得透視圖?
- (void) Draw:
{
// Set the viewport
//glFrustumf(-1.0, 1.0, -1.0/(backingWidth/backingHeight), 1.0/(backingWidth/backingHeight), 0.01, 10.0);
glViewport (0, 0, backingWidth, backingHeight);
// Clear the color buffer
glClear (GL_COLOR_BUFFER_BIT);
if([context API] == kEAGLRenderingAPIOpenGLES2)
[self DrawES2];
else
[self DrawES1];
glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(GLubyte), GL_UNSIGNED_BYTE, indices);
}
- (void) DrawES2
{
// Use the program object
glUseProgram (programObject);
// Load the vertex data
glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
glEnableVertexAttribArray (0);
// Load transformation matrix
GLint mvpLoc = glGetUniformLocation(programObject, "u_mvpMatrix");
glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, yRotation);
}
- (void) DrawES1
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(45, 0, 1, 0);
glVertexPointer(3, GL_FLOAT, 0, vVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(1.0, 0.0, 0.0, 1.0);
}
我得到的是這樣的: enter link description here
我想是這樣的: enter link description here
當我取消了glFrustum線我得到ES1版本中沒有變化,ES2版本中的應用程序崩潰。我是OpenGL的新手,所以我想我可能會做一些非常錯誤的事情,但是如何獲得透視圖以便多維數據集看起來正確?