问题描述
请注意我的代码...。
#include<windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
static GLfloat spin = 0.0; // Does it use as global variable??
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushmatrix();
glColor3f(1.0,1.0,1.0);
glrectf(-25.0,-4.0,25.0,4.0);
glrectf(-4.0,-25.0,4.0,25.0);
glColor3f(0.0,0.0,1.0);
glutSolidTorus(1.00,6.4,10,100);
glPopMatrix();
glFlush();
}
void spindisplay_right1(void)
{
spin = -.60;
glutPostRedisplay();
glrotatef(spin,1.0);
}
注意: 我认为静态变量用作全局变量。如果我在任何函数下使用静态变量,那么它将是局部变量
我对吗? 请回答我的问题。
解决方法
在您的情况下,static GLfloat spin = 0.0;
是一个全局变量,仅在声明该文件的文件中“可见”。
如果在函数内部声明静态变量,则它将是 local 变量,但它将在函数调用之间保留其值。