opengl中 先用glFlush();然后glutSwapBuffers();有什么作用啊

来源:百度知道 编辑:UC知道 时间:2024/05/15 06:37:33
代码中
。。。
glFlush();
glutSwapBuffers();
这样有什么作用啊,难道不重复?
我是新手,请指教

楼上照抄MSDN,请自重

简单地说glFlush就是强制刷新吧,要知道OPENGL是使用一条渲染管线线性处理命令的,一般情况下,我们提交给OPENGL的指令并不是马上送到驱动程序里执行的,而是放到一个缓冲区里面,等这个缓冲区满了再一次过发到驱动程序里执行;很多时候只有几条指令是填充不满那个缓冲区的,这就是说这些指令根本没有被发送到驱动里,所以我们要调用glFlush来强制把这些指令送到驱动里进行处理。

glutSwapBuffers其实就是交换缓冲区啦,估计是你的程序使用的是双缓冲技术吧;用了这种技术的话,你所有的绘制都是绘制到一个后台的缓冲区里面的,如果不交换缓冲区,就看不到绘制的东西了,就这么回事~

来自MSDN:
glFlush
The glFlush function forces execution of OpenGL functions in finite time.

void glFlush( void );
Parameters
This function has no parameters.

Remarks
Different OpenGL implementations buffer commands in several different locations, including network buffers and the graphics accelerator itself. The glFlush function empties all these buffers, causing all issued commands to be executed as quickly as they are accepted by the actual rendering engine. Though this execution may not be completed in any particular time period, it does complete in a finite amount of time.

Because any OpenGL prog