笔记:OpenGL SuperBible - First Program

来源:互联网 发布:王宏安 软件所 编辑:程序博客网 时间:2024/05/21 11:18



// Include the "sb6.h" header file#include "sb6.h"// Derive my_application from sb6::applicationclass 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_MAINDECLARE_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 caseGL_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 drawBufferis 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 functionvoid 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);}


REFERENCE: OpenGL SuperBible 6th

0 0
原创粉丝点击