glClear

1. glClear

Bitwise OR of masks that indicate the buffers to be cleared. The four masks are as follows. Mask Buffer to be Cleared 可以使用|运算符组合不同的缓冲标志位,表明需要清除的缓冲,例如glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)表示要清除颜色缓冲以及深度缓冲

glClear

The glClear function clears buffers to preset values.

void glClear(

GLbitfield mask

);

 

参数

Parameters

mask当前可写的颜色缓冲

GL_DEPTH_BUFFER_BIT The depth buffer.深度缓冲

GL_ACCUM_BUFFER_BIT The accumulation buffer.累积缓冲

GL_STENCIL_BUFFER_BIT The stencil buffer.模板缓冲

 

//注释

Remarks

The glClear function sets the bitplane area of the window to values previously selected by glClearColor, glClearIndex, glClearDepth, glClearStencil, and glClearAccum. You can clear multiple color buffers simultaneously by selecting more than one buffer at a time using glDrawBuffer.

The pixel-ownership test, the scissor test, dithering, and the buffer writemasks affect the operation of glClear. The scissor box bounds the cleared region. The alpha function, blend function, logical operation, stenciling, texture mapping, and z-buffering are ignored by glClear.

The glClear function takes a single argument (mask) that is the bitwise OR of several values indicating which buffer is to be cleared.

The value to which each buffer is cleared depends on the setting of the clear value for that buffer.

If a buffer is not present, a glClear call directed at that buffer has no effect.

The following functions retrieve information related to glClear:

glGet with argument GL_ACCUM_CLEAR_VALUE

glGet with argument GL_DEPTH_CLEAR_VALUE

glGet with argument GL_INDEX_CLEAR_VALUE

glGet with argument GL_COLOR_CLEAR_VALUE

glGet with argument GL_STENCIL_CLEAR_VALUE

以下参考机械工业出版社的《OpenGL编程指南》第五版p18-p20。

glClear()语句的作用是用当前缓冲区清除值,也就是glClearColor或者glClearDepth等函数所指定的值来清除指定的缓冲区。比如:

glClearColor(0.0,0.0,0.0,0.0);

glClear(GL_COLOR_BUFFER_BIT);

第一条语句表示清除颜色设为黑色,第二条语句表示把整个窗口清除为当前的清除颜色,glClear()的唯一参数表示需要被清除的缓冲区。

#include #include "stdafx.h" #define GLUT_DISABLE_ATEXIT_HACK #include //#pragma comment(lib, "glut32.lib") GLfloat AngleX;//旋转向量 GLfloat AngleY; void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); //这个函数其实就是对接下来要做什么进行一下声明 GL_MODELVIEW 模型视图 glLoadIdentity(); glPushMatrix();// 提供了相应的接口 { glRotatef(AngleX, 1.0f, 0.0f, 0.0f); glRotatef(AngleY, 0.0f, 1.0f, 0.0f); glBegin(GL_POLYGON); //前表面 glColor3f(1.0f,1.0f,1.0f);//颜色设置为白色 glVertex3f(50.0f, 50.0f, 50.0f); glColor3f(1.0f,1.0f,0.0f);//颜色设置为黄色 glVertex3f(50.0f, -50.0f, 50.0f); glColor3f(1.0f,0.0f,0.0f);//颜色设置为红色 glVertex3f(-50.0f, -50.0f, 50.0f); glColor3f(1.0f,0.0f,1.0f);//颜色设置为品红色 glVertex3f(-50.0f, 50.0f, 50.0f); glEnd(); glBegin(GL_POLYGON); //后表面 glColor3f(0.0f, 1.0f, 1.0f);//颜色设置为青色 glVertex3f(50.0f, 50.0f, -50.0f); glColor3f(0.0f, 1.0f, 0.0f);//颜色设置为绿色 glVertex3f(50.0f, -50.0f, -50.0f); glColor3f(0.0f, 0.0f, 0.0f);//颜色设置为黑色 glVertex3f(-50.0f, -50.0f, -50.0f); glColor3f(0.0f, 0.0f, 1.0f);//颜色设置为蓝色 glVertex3f(-50.0f, 50.0f, -50.0f); glEnd(); glBegin(GL_POLYGON); //右表面 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte)255);//颜色设置为白色 glVertex3f(50.0f, 50.0f, 50.0f); glColor3f(0.0f, 1.0f, 1.0f);//颜色设置为青色 glVertex3f(50.0f, 50.0f, -50.0f); glColor3f(0.0f, 1.0f, 0.0f);//颜色设置为绿色 glVertex3f(50.0f, -50.0f, -50.0f); glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte)0);//颜色设置为黄色 glVertex3f(50.0f, -50.0f, 50.0f); glEnd(); glBegin(GL_POLYGON); //左表面 glColor3d(0.0, 0.0, 1.0);//颜色设置为蓝色 glVertex3f(-50.0f, 50.0f, -50.0f); glColor3f(0.0f, 0.0f, 0.0f);//颜色设置为黑色 glVertex3f(-50.0f, -50.0f, -50.0f); glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0);//颜色设置为红色 glVertex3f(-50.0f, -50.0f, 50.0f); glColor3f(1.0f, 0.0f, 1.0f);//颜色设置为品红色 glVertex3f(-50.0f, 50.0f, 50.0f); glEnd(); glBegin(GL_POLYGON); //上表面 glColor3d(0.0, 1.0, 1.0);//颜色设置为青色 glVertex3f(50.0f, 50.0f, -50.0f); glColor3d(1.0, 1.0, 1.0);//颜色设置为白色 glVertex3f(50.0f, 50.0f, 50.0f); glColor3d(1.0, 0.0, 1.0);//颜色设置为品红色 glVertex3f(-50.0f, 50.0f, 50.0f); glColor3d(0.0, 0.0, 1.0);//颜色设置为蓝色 glVertex3f(-50.0f, 50.0f, -50.0f); glEnd(); glBegin(GL_POLYGON); //下表面 glColor3f(0.0f, 1.0f, 0.0f);//颜色设置为绿色 glVertex3f(50.0f, -50.0f, -50.0f); glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte)0);//颜色设置为黄色 glVertex3f(50.0f, -50.0f, 50.0f); glColor3f(1.0f, 0.0f, 0.0f);//颜色设置为红色 glVertex3f(-50.0f, -50.0f, 50.0f); glColor3f(0.0f, 0.0f, 0.0f);//颜色设置为黑色 glVertex3f(-50.0f, -50.0f, -50.0f); glEnd(); } glPopMatrix(); glutSwapBuffers(); } void reshape(int w, int h) { GLfloat aspect = (GLfloat)w / (GLfloat)h; GLfloat nRange = 100.0f; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); //将当前矩阵指定为投影模式 glLoadIdentity(); //设置三维投影区 if (w 355.0f) { AngleX = 0.0f; } if (AngleX 355.0f) AngleY = 0.0f; if (AngleY < 0.0f) { AngleY = 355.0f; } glutPostRedisplay(); } void init() { AngleX = 45.0f; AngleY = 315.0f; glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); //初始化OpenGL glEnable(GL_DITHER); //抖动是激活的。 glShadeModel(GL_SMOOTH);//两点间颜色有过渡效果 } void main(int argc, char* argv[]) { glutInit(&argc;, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //使用双缓存 使用深度缓存。 glutInitWindowSize(480, 480); glutCreateWindow("OpenGL颜色立方体"); glutReshapeFunc(reshape); //窗口改变的时候调用的函数 glutDisplayFunc(display); glutSpecialFunc(key_board); //函数注册鼠标响应事件 init(); glutMainLoop(); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值