In OpenGL ES 1.1, you can use glRotatef()
to rotate a model, but that function doesn't exist in OpenGL ES 2.0.
Therefore,开发者_StackOverflow社区 how do you perform rotation in OpenGL ES 2.0?
To follow on what Christian's said, you'll need to keep track of the model view matrix yourself and manipulate that to perform the rotations you need. You'll then pass in the matrix as a uniform to your shader, and do something like the following:
attribute vec4 position;
uniform mat4 modelViewProjMatrix;
void main()
{
gl_Position = modelViewProjMatrix * position;
}
I've found that the Core Animation CATransform3D helper functions work very well for performing the right kind of matrix manipulations needed for this. You can rotate, scale, and translate a CATransform3D, then read out its 4x4 matrix elements to create the model view matrix you need.
If you want to see this in action, this sample iPhone application I created shows how to perform rotation of a cube using both OpenGL ES 1.1 and 2.0.
Whithout the fixed function matrix stacks you have to manage your transformation matrices yourself. Consult some introductory material on matrix and vector algebra, especially with respect to 3d transformations. Then you will understand, what glRotate and the like really do.
精彩评论