Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

opengl - Difference between single buffered(GLUT_SINGLE) and double buffered drawing(GLUT_DOUBLE)

I'm using example here it works under

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

but it become a transparent window when I set it to

glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

but I need that example work with some drawing under GLUT_DOUBLE mode.

So what's the difference between GLUT_DOUBLE and GLUT_SINGLE?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When using GL_SINGLE, you can picture your code drawing directly to the display.

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.

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

So all you should need to do is replace the glFlush() at the end of DrawCube() with glutSwapBuffers() when using GLUT_DOUBLE.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...