yeah, thank you for your detailed explaination, I always thought flip the display and buffer in one frame. It is only correct in single buffer, there is double buffering and even triple , quad buffering. And I really should use drawing black background instead of gl operations. Many thanks!
Simon At 2016-12-13 18:13:50, "Petr Viktorin" <[email protected]> wrote: >Hi, >Pyglet typically uses double buffering [0]: one picture (buffer) is >being drawn, while another is being displayed in the window. Then, they >are flipped, so what was drawn is now displayed, and drawing is done on >the hidden buffer. >This prevents partially-drawn buffers from being displayed. > >So, if you clear every 2 frames, you're only ever clearing one of the >two buffers; the other one continues to accumulate whatever was drawn on it. > >You can tell Pyglet to turn double buffering on or off using context >configuration [1]. (I guess the proper solution would be to draw to a >dedicated buffer, and blit that to the screen. But I've never done that >with Pyglet.) >For your effect, you might also consider drawing a semi-transparent >black rectangle over the screen, rather than clearing every few frames. >But be sure to clear the buffer at the beginning. Some systems don't >start you off with a black window. > > >[0] >https://en.wikipedia.org/wiki/Multiple_buffering#Double_buffering_in_computer_graphics >[1] >http://pyglet.readthedocs.io/en/pyglet-1.2-maintenance/programming_guide/windowing.html > > >On 12/13/2016 07:33 AM, xinming wrote: >> >> >> Sorry, I did not describe my problem clearly. It would work without >> raising errors, however, if I set in odd it would works fine, the >> screenshot here: >> >> >> if set even number, it seemed >> that glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) did not work, so I >> said failed, here is the screenshot if I change 5 to 6. >> >> >> >> >> At 2016-12-13 14:24:01, "..." <[email protected]> wrote: >> >> What do you mean "it failed"? Can you post a traceback or describe >> how the result differs from your expectation? >> >> On Dec 12, 2016 10:34 PM, "Simon" <[email protected] >> <mailto:[email protected]>> wrote: >> >> Hi guys, I met a strange problem. I use pyglet building an app >> to simulate fireworks. And I want to add special effects of >> persistence of vision. I do not know how to do it, I just do it >> in my own way. Maybe you can tell me how to do it. My problem is >> that I update the background >> (glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)) every 3, 5, 7 >> frames, it works. If I update the background every 2,4,6,8 >> frames, it failed. why? >> >> >> my code is like this >> >> >> def on_draw(self): >> glViewport(0, 0, window.width, window.height) >> glMatrixMode(gl.GL_PROJECTION) >> glLoadIdentity() >> gluPerspective(90,window.width/window.height,0.05,1000) >> glMatrixMode(gl.GL_MODELVIEW) >> glLoadIdentity() >> gluLookAt(0.0,0.0,4.0, >> 0.0,0.0,0.0, >> 0.0,1.0,0.0) >> if self.frame % 5 == 1: # >> if change 5 to even number 4,6,8, it failed >> glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) >> >> full code can be found here >> <https://github.com/xinmingzhang/fireworks/blob/master/fireworks.py> >> >> And I am new to OpenGL, I also lost in setting these gl >> environment, like gl.GL_PROJECTION, gl.GL_MODELVIEW etc. >> Sometimes I set the projection, and I see nothing on screen. Is >> there any good suggestions? >> > >-- >You received this message because you are subscribed to the Google Groups >"pyglet-users" group. >To unsubscribe from this group and stop receiving emails from it, send an >email to [email protected]. >To post to this group, send email to [email protected]. >Visit this group at https://groups.google.com/group/pyglet-users. >For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/d/optout.
