I'm trying to apply rotations to stack of textures (working on volume rendering project). My rendering code looks like that:
Code :
static void RenderSceneCB()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
    float viewPortSize = 1.0;
 
    for (int i = 0; i < z; ++i)
    {
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
 
        glRotatef(angleX, 1.0, 0.0, 0.0);
        glRotatef(angleY, 0.0, 1.0, 0.0);
        glRotatef(angleZ, 0.0, 0.0, 1.0);
 
        glMatrixMode(GL_MODELVIEW);
 
        glBindTexture(GL_TEXTURE_2D, texturesObjects[i]);
 
        glBegin(GL_QUADS);
 
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(-viewPortSize, -viewPortSize, 2 * i / static_cast<float>(z)-1);
        glTexCoord2f(1.0f, 0.0f);
        glVertex3f(viewPortSize, -viewPortSize, 2 * i / static_cast<float>(z)-1);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f(viewPortSize, viewPortSize, 2 * i / static_cast<float>(z)-1);
        glTexCoord2f(0.0f, 1.0f);
        glVertex3f(-viewPortSize, viewPortSize, 2 * i / static_cast<float>(z)-1);
 
        glEnd();
        glBindTexture(GL_TEXTURE_2D, 0);
    }
 
    glutSwapBuffers();
}

Those rotations seem to even work, however while rotating along X axis the object after 90 degrees flips and starts to rotate the other way. Secondly, the object magically stretches and does not fit in viewport sometimes. Additionally, I drew 3 vectors imitating axises, and I see that while rotating along X axis or Y axis all of them are floating. Only while rotating along Z axis that vector representing Z axis stands still like it should. I cannot figure out why is this happening.