I have a floating cube that I want to rotate around the Y axis. The cube renders fine, the proper size, the proper coordinate, the proper texture/faces, etc.

However, the rotation is never applied. My update logic calculates a new rotation value, between 0 and 360.

// Set the coordinates, rotate Y axis
GL11.glRotatef(rotation, 0, 1f, 0);

// Each cube face rendered, etc...
GL11.glColor3f( //...

No matter what combination I've tried, the cube never changes it's rotation.

Update Per a comment, I was using glBegin outside the glRotatef and the comment advised that I use glPush/Pop:

    GL11.glRotatef(rotation, 0f, 1f, 0);

  • \$\begingroup\$ glRotatef shouldn't be inside glBegin. From what you have shown it seems so, but you need to show us the rest of the code to be sure. \$\endgroup\$
    – concept3d
    Nov 30 '13 at 20:23
  • \$\begingroup\$ I was using glBegin before the rotate method, but when I try it after, the whole block fails to render. \$\endgroup\$
    – BotskoNet
    Nov 30 '13 at 20:46
  • \$\begingroup\$ your problem is with your loop. You need to understand the matrix stack. But anyway I recommend you abandon the whole OpenGL 1.1 thing because it's useless and start with OpenGL with shaders it will make much more sense. \$\endgroup\$
    – concept3d
    Nov 30 '13 at 20:49
  • \$\begingroup\$ How can I resolve the problem with the loop then? \$\endgroup\$
    – BotskoNet
    Nov 30 '13 at 20:56
  • \$\begingroup\$ you need to understand the matrix stack. specifically glPush, glPop \$\endgroup\$
    – concept3d
    Nov 30 '13 at 21:06

Your problem is the placement of your glPopMatrix call. The current matrix on the stack only affects drawn objects while it is current, but you're drawing after you pop the matrix.

The correct order is:

  • glPushMatrix to go to a new current matrix on the stack.
  • Apply transforms (translate/rotate).
  • Draw objects.
  • glPopMatrix to restore the previous matrix.

Do you see why this is? If not, I'd advise you to review some documentation about how the GL matrix stack works.

  • \$\begingroup\$ I've been reading a lot about the push/pop and rotation methods, I've looked at a ton of example code, and I even tried your example order but I either end up with nothing rendered, or a the block rendered without any rotation. pste.me/C9lTD \$\endgroup\$
    – BotskoNet
    Nov 30 '13 at 22:44
  • \$\begingroup\$ I've finally worked it out. This method worked fine the trouble was that my block was rotating on the offset, meaning it was making a big circle around the map and not its own Y. I turned all blocks invisible to see it during debugging and realized. The final code required two translate commands to rotate on the proper axis. pste.me/QeRyi Thanks \$\endgroup\$
    – BotskoNet
    Nov 30 '13 at 23:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .