OGL?

How would you double buffer an ogl.ShapeCanvas object? I've tried making a separate DC for a buffer (eg bufferdc = wx.BufferedDC(self)) and then using this for the drawing, but when I do diagram.Redraw(self.dc) it either crashes or still flickers.

Is it possible to double buffer an ogl object? Basically, all I want to do is stop the diagram.Redraw() from flickering. Any help is appreciated.

Alex Zeiger wrote:

How would you double buffer an ogl.ShapeCanvas object? I've tried making a separate DC for a buffer (eg bufferdc = wx.BufferedDC(self)) and then using this for the drawing, but when I do diagram.Redraw(self.dc) it either crashes or still flickers.

Is it possible to double buffer an ogl object? Basically, all I want to do is stop the diagram.Redraw() from flickering. Any help is appreciated.

OGL should already be doing some double buffering internally. Perhaps the flicker is coming from a parent window that is not cliping its children properly?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Alex Zeiger wrote:

How would you double buffer an ogl.ShapeCanvas object? I've tried making a separate DC for a buffer (eg bufferdc = wx.BufferedDC(self)) and then using this for the drawing, but when I do diagram.Redraw(self.dc) it either crashes or still flickers.

Is it possible to double buffer an ogl object? Basically, all I want to do is stop the diagram.Redraw() from flickering. Any help is appreciated.

OGL should already be doing some double buffering internally. Perhaps the flicker is coming from a parent window that is not cliping its children properly?

I don't think so. My program is pretty much like the example in the demo. I create and add shapes to a diagram, create and prepare my DC, and then use diagram.Redraw(dc) to draw the diagram whenever a change is made. However, I notice a distinct flickering as each object in the diagram is redrawn.

I've tried numerous things to double buffer the redraw. Unfortunately, I don't fully understand the use of the device context object. The only wx documentation I've found on the net involve basic frame buffering, and don't seem to apply to OGL. However, I've tried following the guide at http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

In my OnSize function, I use:

         self.bitmapbuffer = wx.EmptyBitmap(w, h)

And in my OnPaint, I use:

         self.dc = wx.BufferedPaintDC(self.bitmapbuffer)

My application's a simple board game. So when the user clicks the canvas area, alterations are made to the diagram, and then I call my Draw funcion and perform:

         self.dc = BufferedPaintDC(wx.ClientDC(self), self.bitmapbuffer)
         self.diagram.Redraw(self.dc)

Unfortunately, this buffering attempt produces an infinite stream of errors in the theme of:

Exception exceptions.AttributeError: "wxBufferedPaintDC instance has no attribut
e 'thisown'" in ignored
Traceback (most recent call last):
   File "boardcanvas.py", line 153, in OnPaint
     self.dc = wx.BufferedPaintDC(self.bitmapbuffer)
   File "C:\Python23\lib\site-packages\wxPython\gdi.py", line 1026, in __init__
     self.this = gdic.new_wxBufferedPaintDC(*_args,**_kwargs)
TypeError: Type error in argument 1 of new_wxBufferedPaintDC. Expected _wxWindow
_p.

Alex Zeiger wrote:

Robin Dunn wrote:

I've tried numerous things to double buffer the redraw. Unfortunately, I don't fully understand the use of the device context object. The only wx documentation I've found on the net involve basic frame buffering, and don't seem to apply to OGL. However, I've tried following the guide at http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

In my OnSize function, I use:

        self.bitmapbuffer = wx.EmptyBitmap(w, h)

And in my OnPaint, I use:

        self.dc = wx.BufferedPaintDC(self.bitmapbuffer)

My application's a simple board game. So when the user clicks the canvas area, alterations are made to the diagram, and then I call my Draw funcion and perform:

        self.dc = BufferedPaintDC(wx.ClientDC(self), self.bitmapbuffer)
        self.diagram.Redraw(self.dc)

Unfortunately, this buffering attempt produces an infinite stream of errors in the theme of:

Because you are using the wrong buffered DC class. The wx.BufferedPaintDC is only for use in EVT_PAINT handlers because it makes a wx.PaintDC internally. (Which is why it expects a window for the first arg instead of another DC.)

Try using wx.BufferedDC instead.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Alex Zeiger wrote:

Robin Dunn wrote:

I've tried numerous things to double buffer the redraw. Unfortunately, I don't fully understand the use of the device context object. The only wx documentation I've found on the net involve basic frame buffering, and don't seem to apply to OGL. However, I've tried following the guide at http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

In my OnSize function, I use:

        self.bitmapbuffer = wx.EmptyBitmap(w, h)

And in my OnPaint, I use:

        self.dc = wx.BufferedPaintDC(self.bitmapbuffer)

My application's a simple board game. So when the user clicks the canvas area, alterations are made to the diagram, and then I call my Draw funcion and perform:

        self.dc = BufferedPaintDC(wx.ClientDC(self), self.bitmapbuffer)
        self.diagram.Redraw(self.dc)

Unfortunately, this buffering attempt produces an infinite stream of errors in the theme of:

Because you are using the wrong buffered DC class. The wx.BufferedPaintDC is only for use in EVT_PAINT handlers because it makes a wx.PaintDC internally. (Which is why it expects a window for the first arg instead of another DC.)

Try using wx.BufferedDC instead.

Should that be in my draw handler or my paint handler? I've tried all four combinations, yet every time I get the continual error:

TypeError: new_wxBufferedDC() takes exactly 2 arguments (1 given)
Exception exceptions.AttributeError: "wxBufferedDC instance has no attribute 'thisown'" in ignored
Traceback (most recent call last):
   File "C:\Documents and Settings\Administrator\My Documents\tech\gomen\source\b
oardcanvas.py", line 136, in OnPaint
     self.dc = wx.BufferedDC(self.bitmapbuffer)
   File "C:\Python23\lib\site-packages\wxPython\gdi.py", line 1005, in __init__
     self.this = gdic.new_wxBufferedDC(*_args,**_kwargs)

wxBufferedDC isn't listed in the OGL reference docs, so I'm not sure what argument I'm missing.

Alex Zeiger wrote:

Should that be in my draw handler or my paint handler?

In the draw handler. As I said before the wx.BufferedPaintDC is to be used in the EVT_PAINT handlers.

I've tried all four combinations, yet every time I get the continual error:

TypeError: new_wxBufferedDC() takes exactly 2 arguments (1 given)
Exception exceptions.AttributeError: "wxBufferedDC instance has no attribute 'thisown'" in ignored
Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\My Documents\tech\gomen\source\b
oardcanvas.py", line 136, in OnPaint
    self.dc = wx.BufferedDC(self.bitmapbuffer)

You need to pass the client DC as the first parameter, so the buffer DC knows where to Blit to when you are done drawing. Also, you should not save a reference to the DC in self. DCs in general are meant to be used and then thrown away, and buffered DCs in particular require it because they flush the bitmap to the real DC when the buffered DC is destroyed.

  File "C:\Python23\lib\site-packages\wxPython\gdi.py", line 1005, in __init__
    self.this = gdic.new_wxBufferedDC(*_args,**_kwargs)

wxBufferedDC isn't listed in the OGL reference docs, so I'm not sure what argument I'm missing.

It's not part of OGL. They are documented in the wx 2.5 docs:

http://wxwidgets.org/manuals/2.5.1/wx_wxbuffereddc.html
http://wxwidgets.org/manuals/2.5.1/wx_wxbufferedpaintdc.html

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!