【问题标题】:what is the use of static variable in Opengl?Opengl中静态变量的用途是什么?
【发布时间】:2020-12-17 23:06:20
【问题描述】:

请注意我的代码......

#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, 0.0, 0.0, 1.0);
}

注意: 我认为静态变量用作全局变量。如果我在任何函数下使用静态变量,那么它将是局部变量

我说的对吗? 请回答我的问题。

【问题讨论】:

标签: c++ global-variables local-variables static-variables


【解决方案1】:

在您的情况下,static GLfloat spin = 0.0; 是一个 全局 变量,只能在声明它的文件中“看到”。

如果你在函数中声明一个静态变量,那么它将是一个局部变量,但它会在函数调用之间保持其值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 2016-06-25
    • 2010-09-20
    • 2010-12-21
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    相关资源
    最近更新 更多