Shows the DrawGeometry function, which draws all the geometry of the scene.
The RenderScene function then repeatedly calls this function and accumulates the results into the accumulation buffer. When that process is finished, the lines
glAccum(GL_RETURN, 1.0f);
glutSwapBuffers();
copy the accumulation buffer back to the color buffer and perform the buffer swap.
Using the Accumulation Buffer for Motion Blur:
/////////////////////////////////////////////////////////////
// Draw the ground and the revolving sphere
void DrawGeometry(void) {
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
DrawGround();
// Place the moving sphere
glColor3f(1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.5f, -3.5f);
glRotatef(-(yRot * 2.0f), 0.0f, 1.0f, 0.0f);
glTranslatef(1.0f, 0.0f, 0.0f);
glutSolidSphere(0.1f, 17, 9);
glPopMatrix();
}
///////////////////////////////////////////////////////////////////////
// Called to draw scene. The world is drawn multiple times with each
// frame blended with the last. The current rotation is advanced each
// time to create the illusion of motion blur.
void RenderScene(void) {
GLfloat fPass;
GLfloat fPasses = 10.0f;
// Set the current rotation back a few degrees
yRot = 35.0f;
for (fPass = 0.0f; fPass < fPasses; fPass += 1.0f) {
yRot += .75f; //1.0f / (fPass+1.0f);
// Draw sphere
DrawGeometry();
// Accumulate to back buffer
if (fPass == 0.0f)
glAccum(GL_LOAD, 0.5f);
else
glAccum(GL_ACCUM, 0.5f * (1.0f / fPasses));
}
// copy accumulation buffer to color buffer and
// do the buffer Swap
glAccum(GL_RETURN, 1.0f);
glutSwapBuffers();
}
Operation Description
GL_ACCUM Scales the color buffer values by value and adds them to the current contents of the accumulation buffer.
GL_LOAD Scales the color buffer values by value and replaces the current contents of the accumulation buffer.
GL_RETURN Scales the color values from the accumulation buffer by value and then
copies the values to the color buffer.
GL_MULT Scales the color values in the accumulation buffer by value and stores the
result in the accumulation buffer.
GL_ADD Scales the color values in the accumulation buffer by value and adds the
result to the current accumulation buffer contents.
How to scale: ***