OpenGL glcolor for循环

时间:2012-09-20 20:52:41

标签: c opengl for-loop

我正在尝试绘制一个洛伦兹吸引子,其中颜色在整个吸引子中发生变化。我写了以下for循环来计算吸引点。

    float x = 1, y = 1, z = 1;
    glBegin(GL_LINE_STRIP);

    int i;    
    for (i=0; i < initialIterations; i++) {
        glColor3d(0,i/50000,1);
        // compute a new point using the lorenz attractor equations
        float dx = sigma*(y-x);
        float dy = x*(r-z) - y;
        float dz = x*y - b*z;

        // save the new point
        x = x + dx*dt;
        y = y + dy*dt;
        z = z + dz*dt;        

        glVertex3f(x/50,y/50,z/50);
    }
    glEnd();

我使用代码顶部的glcolor将颜色更改为i的函数。但是,我没有看到我想要的结果,我得到的只是一种纯色。我知道颜色就像状态机一样,但我需要找到一种改变颜色的方法。

1 个答案:

答案 0 :(得分:4)

你正在进行整数除法:i/50000,所以它总是为0。

尝试i/50000.0