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
  • 49,394
  • 10
  • 79
  • 128
snakile
  • 50,186
  • 60
  • 164
  • 235

2 Answers2

31

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,510
  • 1
  • 35
  • 52
3

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

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

OpenGL Rotation

eouw0o83hf
  • 9,080
  • 4
  • 55
  • 70
karlphillip
  • 89,883
  • 35
  • 240
  • 408
  • 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