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

genpfault
  • 51,148
  • 11
  • 85
  • 139
snakile
  • 52,936
  • 62
  • 169
  • 241

2 Answers2

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 ...
Jay Kominek
  • 8,674
  • 1
  • 34
  • 51
4

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

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

OpenGL Rotation

eouw0o83hf
  • 9,438
  • 5
  • 53
  • 75
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • 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 May 30 '21 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. – karlphillip May 31 '21 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 Jun 01 '21 at 17:24