我在與旋轉的麻煩。我可以讓立方體旋轉得很好,但我只希望立方體旋轉。我知道我必須使用glPushMatrix()和glPopMatrix(),但每次我在繪圖周圍包裝這兩個圖形時,它都會停止旋轉。glPushMatrix停止所有旋轉的發生
下面是我設立的OpenGL:
void initOpenGL()
{
//these are the current version of OpenGL
string versions[14] =
{
"GL_VERSION_1_1",
"GL_VERSION_1_2",
"GL_VERSION_1_3",
"GL_VERSION_1_4",
"GL_VERSION_1_5",
"GL_VERSION_2_0",
"GL_VERSION_2_1",
"GL_VERSION_3_0",
"GL_VERSION_3_1",
"GL_VERSION_3_2",
"GL_VERSION_3_3",
"GL_VERSION_4_0",
"GL_VERSION_4_1",
"GL_VERSION_4_2"
};
//Determine which versions are safe to use
cerr << "OpenGL+GLEW Info: " << endl;
for (int i = 0; i < 14; ++i)
{
if (glewIsSupported(versions[i].c_str()))
cerr << versions[i] << " is supported" << endl;
else
cerr << "ERROR: " << versions[i] << " is not supported" << endl;
}
cerr << endl << "Open GL " << glGetString (GL_VERSION) << " is the current OpenGL version" << endl << endl;
glClearColor(0, 0, 0, 0);
//By setting this option, we can explicityly control how the program terminates to ensure proper cleanup
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
//setup the camera
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(MIN_X, MAX_X, MIN_Y, MAX_Y, MIN_Z, MAX_Z);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//enable access to the alpha channel
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
... some more code to load textures...
}
這裏是我的顯示功能:
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1, 0, 0);
glRotatef(angle, 1, 1, 0);
glutSolidCube(30);
glPopMatrix();
glutSwapBuffers();
}
我只是打周圍的一些更多的,和glPopMatrix();是顯示的行,停止發生旋轉。任何想法可能會發生什麼? – Steven 2012-07-16 04:15:02