I\'m using example here it works under
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
but it become a transparent window when I set it to
When drawing to a single buffered context (GLUT_SINGLE), there is only one framebuffer that is used to draw and display the content. This means, that you draw more or less directly to the screen. In addition, things draw last in a frame are shown for a shorter time period then objects at the beginning.
In a double buffered scenario (GLUT_DOUBLE), there exist two framebuffer. One is used for drawing, the other one for display. At the end of each frame, these buffers are swapped. Doing so, the view is only changed at once when a frame is finished and all objects are visible for the same time.
That beeing said: Are you sure that a transparent window is caused by GL_DOUBLE and not by using GL_RGBA instead of GL_RGB?
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
.