opengl中 先用glFlush();然后glutSwapBuffers();有啥作用啊
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opengl中 先用glFlush();然后glutSwapBuffers();有啥作用啊相关的知识,希望对你有一定的参考价值。
代码中
。。。
glFlush();
glutSwapBuffers();
这样有什么作用啊,难道不重复?
我是新手,请指教
简单地说glFlush就是强制刷新吧,要知道OPENGL是使用一条渲染管线线性处理命令的,一般情况下,我们提交给OPENGL的指令并不是马上送到驱动程序里执行的,而是放到一个缓冲区里面,等这个缓冲区满了再一次过发到驱动程序里执行;很多时候只有几条指令是填充不满那个缓冲区的,这就是说这些指令根本没有被发送到驱动里,所以我们要调用glFlush来强制把这些指令送到驱动里进行处理。
glutSwapBuffers其实就是交换缓冲区啦,估计是你的程序使用的是双缓冲技术吧;用了这种技术的话,你所有的绘制都是绘制到一个后台的缓冲区里面的,如果不交换缓冲区,就看不到绘制的东西了,就这么回事~ 参考技术A 来自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 program might be executed over a network, or on an accelerator that buffers commands, be sure to call glFlush in any programs requiring that all of their previously issued commands have been completed. For example, call glFlush before waiting for user input that depends on the generated image.
The glFlush function can return at any time. It does not wait until the execution of all previously issued OpenGL functions is complete.
SwapBuffers
The SwapBuffers function exchanges the front and back buffers if the current pixel format for the window referenced by the specified device context includes a back buffer.
BOOL SwapBuffers(
HDC hdc // device context whose buffers get swapped
);
Parameters
hdc
Specifies a device context. If the current pixel format for the window referenced by this device context includes a back buffer, the function exchanges the front and back buffers.
Return Values
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.
Remarks
If the current pixel format for the window referenced by the device context does not include a back buffer, this call has no effect and the content of the back buffer is undefined when the function returns.
With multithread applications, flush the drawing commands in any other threads drawing to the same window before calling SwapBuffers.
找不到任何 GLU 文档
【中文标题】找不到任何 GLU 文档【英文标题】:Cannot find any GLU documentation 【发布时间】:2014-04-03 08:20:26 【问题描述】:我在 Internet 上找不到任何指向“官方”GLU 下载或文档的链接。 opengl.org 上有关 GLU 的链接已失效。我在 MSDN 上找到的唯一 GLU API 文档是关于 Windows 版本的 GLU。是否有“官方”GLU 页面以及 Linux 的文档和下载之类的页面?
【问题讨论】:
【参考方案1】:http://www.opengl.org/sdk/docs/man2/
GLU 文档是 OpenGL 2 文档的一部分。有a special section for GLU functions。
【讨论】:
看起来 GLU 不再实际了。以上是关于opengl中 先用glFlush();然后glutSwapBuffers();有啥作用啊的主要内容,如果未能解决你的问题,请参考以下文章
Windows 上的 CMake - 使用导入的目标 OpenGL::GLU 时 FindOpenGL.cmake 中的错误?