0

I am trying to draw spheres to the screen without removing them (to get some king of "trails" effect) with OpenGL (glut).

I also have text on the screen which I want to be able to read, so I must manually draw a black rectangle over the old text and then draw the new one.

The point is I also want to turn the "trails" on/off while running, but Ive encountered a very weird problem:

When I used single buffering, everything went just fine, but when I switched to double buffering and used only the front buffer, I started to get flickering on the text. This happened only in fullscreen. In windowed mode with the same resolution(1920x1080) there is no flickering, although I get the same fps (about 250).

Does anybody know what is causing this and why?

Bart
  • 19,692
  • 7
  • 68
  • 77
  • What does "used only the front buffer" mean? Are you using `glutSwapBuffers()`, that is how to avoid flicker in double-buffered applications. – psalvaggio Apr 03 '12 at 18:16
  • No, just the opposite. I avoid using the glutSwapBuffers, to get single-buffering. I want to be able to switch between single, and double buffering. I need single buffering to get the trail effect without drawing everything twice. – John Smith Apr 03 '12 at 18:19
  • 1
    I was always under the impression that you switched between the two by passing `GLUT_SINGLE` or `GLUT_DOUBLE` to `glutInitDisplayMode`. I found this example, maybe it can be of help: http://www.sgi.com/products/software/opengl/examples/glut/examples/source/sb2db.c – psalvaggio Apr 03 '12 at 18:22
  • I just tried that, and it actually worked.... Never thought of doing something like this. Thank you! – John Smith Apr 03 '12 at 18:52

1 Answers1

1

The whole idea of double buffering is explained in this wikipedia article. I'm not sure why you don't see any problems without double buffering but as far as I understand your question, you need to use double buffering properly.

edit: you might be interested in answers to Is double buffering needed any more. This answer to PiP in OpenGL causing flickering also could be relevant to your program.

Community
  • 1
  • 1
akostadinov
  • 17,364
  • 6
  • 77
  • 85
  • I know the idea of double buffering, but as I said, I want sometimes to get the "trail" effect. If I used the double-buffering, I would need to draw everything twice. – John Smith Apr 03 '12 at 18:24
  • Also, it doesn't explain why this only happens in full-screen mode – John Smith Apr 03 '12 at 18:24
  • wrt drawing twice - double buffering is more cpu/mem intensive;; wrt flickering on the text - that's expected since you also say you first draw black over the old text and then draw text again;; wrt **not** flickering in window mode - I am wondering what OS are you using, when I used windows a long ago I noticed big difference in windowed vs non-windowed app performance. I am guessing that seeing or not seeing flicker would be platform dependent. Perhaps try and see what happens on another platform or at least another machine? – akostadinov Apr 03 '12 at 19:02
  • wrt flickering on the text - I did the same when I used Single Buffer mode, and there was no flickering even in fullscreen. wrt not flickering - I tried that on several different versions of windows on several different computers with the same result. I use the Windows library, and it would be quite a mess to start using another library now.... I found a possible way to "bypass" the problem by using two windows, like psalvaggio mentioned above, but I still don't understand why manually using one buffer in doublebuffer and fullscreen mode, makes flickering to appear. – John Smith Apr 03 '12 at 19:41
  • I don't know the internals of how exactly is your app written and how windows handles fullscreen/windowed mode. But in any case it is all about timing on the particular platform you are using. If you draw black over your text, then it is a matter of time that black to be shown on screen. It's also about time if drawing the new text will show up on screen at the same moment. That's platform and environment specific. So if it doesn't flicker on one or a number of machines/platforms, this doesn't mean it is going to work the same everywhere. That might be perfectly fine for your use case though. – akostadinov Apr 04 '12 at 05:53