单缓冲(GLUT_SINGLE)和双缓冲绘图(GLUT_DOUBLE)的区别 [英] Difference between single buffered(GLUT_SINGLE) and double buffered drawing(GLUT_DOUBLE)

查看:31
本文介绍了单缓冲(GLUT_SINGLE)和双缓冲绘图(GLUT_DOUBLE)的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里使用 示例 它在

I'm using example here it works under

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_DOUBLEGLUT_SINGLE 有什么区别?

So what's the difference between GLUT_DOUBLE and 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() 的参数中指定不同的标志外,主要区别在于您在显示函数末尾进行的调用.这是用glutDisplayFunc()注册的函数,也就是你链接的代码中的DrawCube().

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();
    

  • 所以你需要做的就是在使用时将 DrawCube() 末尾的 glFlush() 替换为 glutSwapBuffers()GLUT_DOUBLE.

    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)的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆