Difficulties adjusting to OpenGL on the Mac
I know OpenGL itself is a frequently asked question, but I couldn't find a solution to this specific problem I'm having. I've been following NeHe's tutorials, and I've ran into some issues which I don't think should be happening:
- When calling glRotatef, where the first parameter being the angle, it appears to be the speed of rotation instead.
Example:
glRotatef(0, 0.0f, 1.0f, 0.0f); // despite the constant numbers, the object rotates infinitely
I am using an NSTimer to loop through the drawing method, which I may think be part of the issue.
- Instead of the object rotating 360 degrees around like it should, the object's angle will increment to 180 then decrement back to 0. This is the same with 2D and 3D objects.
I 开发者_Python百科saw example code from Apple and other places that didn't have the same problem as I did, but I was never able to figure out what exactly I am doing wrong that gives me these issues.
The code you have there glRotatef(0,0.0f,1.0f,0.0f);
does not change the rotation at all, it simply requests a rotation of 0 degrees around the Y axis. If you want an object to rotate smoothly as time progresses I would suggest the following:
Keep a counter that increments every time your timer triggers, then, before you draw whatever object you are displaying, reset the transformation matrix with glLoadIdentity()
and then call glRotatef( counter , 0.0f, 1.0f , 0.0f )
精彩评论