问题描述
我正在使用此处的示例在
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
但是当我将其设置为
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
但是我需要该示例在GLUT_DOUBLE
模式下处理某些图形.
but I need that example work with some drawing under GLUT_DOUBLE
mode.
那么GLUT_DOUBLE
和GLUT_SINGLE
有什么区别?
推荐答案
使用GL_SINGLE
时,可以将代码图直接显示在显示器上.
When using GL_SINGLE
, you can picture your code drawing directly to the display.
使用GL_DOUBLE
时,您可以图片有两个缓冲区.其中一个始终可见,而另一个则不可见.您始终渲染到当前不可见的缓冲区.渲染完框架后,交换两个缓冲区,使刚渲染的缓冲区可见.以前可见的那个现在不可见了,您可以用它来渲染下一帧.因此,每帧会颠倒两个缓冲区的作用.
When using GL_DOUBLE
, you can picture having two buffers. One of them is always visible, the other one is not. You always render to the buffer that is not currently visible. When you're done rendering the frame, you swap the two buffers, making the one you just rendered visible. The one that was previously visible is now invisible, and you use it for rendering the next frame. So the role of the two buffers is reversed each frame.
实际上,底层实现在大多数现代系统上的工作方式有所不同.例如,某些平台使用三重缓冲来防止在请求缓冲区交换时阻塞.但这通常与您无关.关键是它的表现表现,就好像您有两个缓冲区一样.
In reality, the underlying implementation works somewhat differently on most modern systems. For example, some platforms use triple buffering to prevent blocking when a buffer swap is requested. But that doesn't normally concern you. The key is that it behaves as if you had two buffers.
除了在glutInitDisplayMode()
的参数中指定不同的标志之外,主要区别在于您在显示函数末尾进行的调用.这是在链接的代码中的DrawCube()
中注册的glutDisplayFunc()
函数.
The main difference, aside from specifying the different flag in the argument for glutInitDisplayMode()
, is the call you make at the end of the display function. This is the function registered with glutDisplayFunc()
, which is DrawCube()
in the code you linked.
-
在单缓冲区模式下,您最终将其称为:
In single buffer mode, you call this at the end:
glFlush();
在双缓冲模式下,您调用:
In double buffer mode, you call:
glutSwapBuffers();
因此,您需要做的就是在使用GLUT_DOUBLE
时用glutSwapBuffers()
替换DrawCube()
末尾的glFlush()
.
So all you should need to do is replace the glFlush()
at the end of DrawCube()
with glutSwapBuffers()
when using GLUT_DOUBLE
.
这篇关于单缓冲(GLUT_SINGLE)与双缓冲工程图(GLUT_DOUBLE)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!