16

I have some objects on the screen and would like to rotate only one of them. I tried using the glRotatef(...) function but turns out glRotatef(...) rotates all my objects (rotates the camera, maybe?). How can I rotate only one?

I use openGL ES 1.1

2 Answers 2

33

You need the rotation to be in effect only when the geometry you're interested in is being drawn.

... draw stuff ...
glPushMatrix();
glRotatef(angle, 0, 1, 0);
... draw rotated stuff ...
glPopMatrix();
... draw more stuff ...
4

Tutorial #4 from NeHe shows how to do that precisely.

Also, you might want to take a look at this:

OpenGL Rotation

3
  • This is highly highly outdated now. Opengl has become lower level and much harder to use. Nowadays people directly write code that runs on the GPU.
    – Brian Yeh
    Commented May 30, 2021 at 16:40
  • @BrianYeh Well, it is a 10 year old question & answer, after all. All posts on Stackoverflow will suffer from aging so it is important that people keep asking questions and new blood like you help come up with relevant answers. Commented May 31, 2021 at 16:22
  • just amending the question for future lurkers who happen upon your answer so they know it's outdated. Totally understood that it's 10 years old.
    – Brian Yeh
    Commented Jun 1, 2021 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.