glAccum到FBO?帮助改变

时间:2014-04-08 21:06:45

标签: c++ glsl shader framebuffer

我一直在网上看这个例子如何在点上获得运动轨迹,但是无法解决我应该使用什么而不是glAccum缓冲区来使用轨迹。

我刚刚开始学习帧缓冲器,这些已弃用的功能并没有让它变得更容易。

void drawGLScene() {     //这些是计算我们的fps ...(记住:静态变量只能被分配一次!)     static GLint t0 = 0;     static GLint frames = 0;

// Clear the draw and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Take the contents of the current accumulation buffer and copy it to the colour buffer with each pixel multiplied by a factor
// i.e. we clear the screen, draw the last frame again (which we saved in the accumulation buffer), then draw our stuff at its new location on top of that
glAccum(GL_RETURN, 0.95f);

// Clear the accumulation buffer (don't worry, we re-grab the screen into the accumulation buffer after drawing our current frame!)
glClear(GL_ACCUM_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Translate everything into the screen (z-axis) by -windowDepth
glTranslatef(0.0f, 0.0f, -windowDepth);

// Apply oscillating rotation to the matrix around the Z-axis.
// Multiplying by 100 is just a fudge factor to increase the total rotation amount
glRotatef(cos(deg2rad(Star::rotationAmount)) * 100, 0.0f, 0.0f, 1.0f);

vector<Star>::iterator starIter; // This needs to be a standard iterator not a constant iterator so we can modify what's being pointed to!!

// Do the actual drawing...
for (starIter = stars.begin(); starIter != stars.end(); starIter++)
{
    // Change the point size to the stars size property
    glPointSize(starIter->getStarSize());

    glBegin(GL_POINTS); // This needs to be inside the loop so the PointSize change (above) takes effect

        // Set the colour
        glColor3f(starIter->getRedComponent(), starIter->getGreenComponent(), starIter->getBlueComponent());

        // Draw the point
        glVertex3f(starIter->getX(), starIter->getY(), starIter->getZ());

    glEnd();

    // Move the star closer (or reset it if it's too close) ready for the next frame
    starIter->moveStar();
}

// Swap the buffers so we can see what we've drawn without -watching- it being drawn
SDL_GL_SwapBuffers();

// Take the contents of the current draw buffer and copy it to the accumulation buffer with each pixel modified by a factor
// The closer the factor is to 1.0f, the longer the trails... Don't exceed 1.0f - you get garbage.
glAccum(GL_ACCUM, 0.9f);

// Calcualate our FPS and display it in the console every five seconds
frames++;
{
    GLint t = SDL_GetTicks();
    if (t - t0 >= 5000)
    {
        GLfloat seconds = (t - t0) / 1000.0;
        GLfloat fps = frames / seconds;
        printf("%d frames in %g seconds = %g FPS\n", frames, seconds, fps);
        t0 = t;
        frames = 0;
    }
}

// Add to the star rotation for the next frame
if (Star::rotationAmount < 360.0f)
{
     // How quickly this value goes up will controll how quickly it rotates...
     // i.e. higher values == faster rotation
    Star::rotationAmount += Star::ROTATION_SPEED;
}
else
{
    Star::rotationAmount = 0.0f;
}

}

我真的很挣扎如何让这个工作,有人帮忙!

0 个答案:

没有答案