// Include the "sb6.h" header file
#include "sb6.h"
// Derive my_application from sb6::application
class my_application : public sb6::application {
public:
// Our rendering function
void render(double currentTime) {
// Simply clear the window with red
static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, red);
}
};
// Our one and only instance of DECLARE_MAIN
DECLARE_MAIN(my_application);
注解:
1、函数 glClearBufferfv 原型:
void glClearBufferfv(GLenum buffer,GLint drawBuffer,
const GLfloat * value);
glClearBufferfv()
tells
OpenGL to clear the buffer specifiedby the first parameter (in this case
GL
_
COLOR
) to the value specified in itsthird parameter. The second parameter,
drawBuffer
, is used when there are multiple output buffers that could be cleared. Because we’re only using one here and
drawBuffer
is a zero-based index, we’ll just set it to zero in this example.
2、currentTime:
the number ofseconds since the application was started, and we can use it to create asimple animation.
The following example use it to change colour for clearing the window:
Animating color over time:
// Our rendering function
void render(double currentTime) {
const GLfloat color[] = { (float)sin(currentTime) * 0.5f + 0.5f, (float)cos(currentTime) * 0.5f + 0.5f,
0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, color);
}