2 csdn dchen csdn_dchen 于 2015.07.03 14:01 提问

麻烦解释下代码的含义

#include
GLfloat xRotated, yRotated, zRotated;
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0,0.0,-4.0);
glRotatef(xRotated,1.0,0.0,0.0);
glRotatef(yRotated,0.0,1.0,0.0);
glRotatef(zRotated,0.0,0.0,1.0);
//glScalef(2.0,1.0,1.0);
glutWireCube(1.5);
glFlush(); //Finish rendering
glutSwapBuffers();
}
void Reshape(int x, int y)
{
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Angle of view:40 degrees
//Near clipping plane distance: 0.5
//Far clipping plane distance: 20.0
gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y); //Use the whole window for rendering
}
static int times = 0;
void Idle(void)
{
times++;
if(times >30000)
times = 0;
if(times %30000 == 0) { xRotated += 0.3; yRotated += 0.1; zRotated += -0.4; Display(); }
}
int main (int argc, char **argv)
{
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //For animations you should use double buffering
glutInitWindowSize(300,300);
//Create a window with rendering context and everything else we need
glutCreateWindow("Cube example");
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
xRotated = yRotated = zRotated = 0.0;
glClearColor(0.5,0.5,0.0,0.0);
//Assign the two used Msg-routines
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutIdleFunc(Idle);
//Let GLUT get the msgs
glutMainLoop();
return 0;
}

3个回答

frank_20080215
frank_20080215   2015.07.03 14:24

创建一个窗体
,然后窗体不停地转动

caozhy
caozhy   Ds   Rxr 2015.07.03 22:24

opengl自带的旋转六面体的例子程序。

91program
91program   Ds   Rxr 2015.07.05 15:55

代码的含义,想要搞清楚的话,最好是先搞清楚调用的函数的功能。这些函数,在 opengl 的帮助中都能查到。
查不到就是自己定义的,然后看代码的逻辑。

Csdn user default icon
上传中...
上传图片
插入图片