コード例 #1
0
class FBOWindow(PyprocessingWindow):
    """This is a pyglet window where drawing in fact occurs inside an FBO.
    The flip method is overridden so that instead of merely swapping the
    back and front buffers, the FBO is first blitted onto the back buffer.
    The idea is to provide a stable drawing canvas which is not erased or
    corrupted by the flip."""
    def __init__(self, *args, **keyargs):
        """Constructor"""
        # construct the base class
        super(FBOWindow, self).__init__(*args, **keyargs)
        # construct the fbo and attach it
        self.fbo = FBO(self.width, self.height)
        self.fbo.attach()

    def flip(self):
        """Override the flip method."""
        # cease using the FBO and start using the regular frame buffer
        self.fbo.detach()
        # save the OpenGL state
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glPushAttrib(GL_ALL_ATTRIB_BITS)
        glViewport(0, 0, self.width, self.height)
        # Draws a quad with the fbo as a texture
        glDisable(GL_BLEND)
        glDisable(GL_DEPTH_TEST)
        glDisable(GL_LIGHTING)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
        glEnable(GL_TEXTURE_2D)
        glColor3f(1, 1, 1)
        glBindTexture(GL_TEXTURE_2D, self.fbo.img)
        glBegin(GL_QUADS)
        for v, t in [((-1, -1, 0), (0, 0)), ((-1, 1, 0), (0, 1)),
                     ((1, 1, 0), (1, 1)), ((1, -1, 0), (1, 0))]:
            glTexCoord2f(*t)
            glVertex3f(*v)
        glEnd()
        # restore the state
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        glPopAttrib()

        # do the actual flip
        super(FBOWindow, self).flip()
        # reattach the fbo for further drawing
        self.fbo.attach()

    def on_resize(self, w, h):
        super(FBOWindow, self).on_resize(w, h)
        self.fbo.detach()
        self.fbo = FBO(w, h)
        self.fbo.attach()
コード例 #2
0
ファイル: flippolicy.py プロジェクト: msarch/py
class FBOWindow(PyprocessingWindow):
    """This is a pyglet window where drawing in fact occurs inside a FBO.
    The flip method is overridden so that instead of merely swapping the
    back and front buffers, the FBO is first blitted onto the back buffer.
    The idea is to provide a stable drawing canvas which is not erased or
    corrupted by the flip."""
    def __init__(self, *args, **keyargs):
        """Constructor"""
        # construct the base class
        super(FBOWindow, self).__init__(*args, **keyargs)
        # construct the fbo and attach it
        self.fbo = FBO(self.width, self.height)
        self.fbo.attach()

    def flip(self):
        """Override the flip method."""
        # cease using the FBO and start using the regular frame buffer
        self.fbo.detach()
        # save the OpenGL state
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glViewport(0, 0, self.width, self.height)
        # prepares and blits the FBO buffer onto the back buffer.
        glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, self.fbo.framebuffer)
        glReadBuffer(GL_COLOR_ATTACHMENT0_EXT)
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0)
        glDrawBuffer(GL_BACK)
        glBlitFramebufferEXT(0, 0, self.width, self.height, 0, 0, self.width,
                             self.height, GL_COLOR_BUFFER_BIT, GL_NEAREST)
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        # do the actual flip
        super(FBOWindow, self).flip()
        # reattach the fbo for further drawing
        self.fbo.attach()

    def on_resize(self, w, h):
        super(FBOWindow, self).on_resize(w, h)
        self.fbo.detach()
        self.fbo = FBO(w, h)
        self.fbo.attach()
コード例 #3
0
ファイル: flippolicy.py プロジェクト: travisfw/pyprocessing
class FBOWindow(PyprocessingWindow):
    """This is a pyglet window where drawing in fact occurs inside a FBO.
    The flip method is overridden so that instead of merely swapping the
    back and front buffers, the FBO is first blitted onto the back buffer.
    The idea is to provide a stable drawing canvas which is not erased or
    corrupted by the flip."""
    
    def __init__(self, *args, **keyargs):
        """Constructor"""
        # construct the base class
        super(FBOWindow, self).__init__(*args, **keyargs)
        # construct the fbo and attach it
        self.fbo = FBO(self.width, self.height)
        self.fbo.attach()
        
    def flip(self):
        """Override the flip method."""
        # cease using the FBO and start using the regular frame buffer
        self.fbo.detach()
        # save the OpenGL state
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glViewport(0,0,self.width,self.height)
        # prepares and blits the FBO buffer onto the back buffer.
        glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, self.fbo.framebuffer)
        glReadBuffer(GL_COLOR_ATTACHMENT0_EXT)
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0)
        glDrawBuffer(GL_BACK)
        glBlitFramebufferEXT(0, 0, self.width, self.height, 0, 0, self.width, self.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        # do the actual flip
        super (FBOWindow, self).flip()
        # reattach the fbo for further drawing
        self.fbo.attach()
        
    def on_resize(self,w,h):
        super (FBOWindow, self).on_resize(w,h)
        self.fbo.detach()
        self.fbo = FBO(w,h)
        self.fbo.attach()
コード例 #4
0
ファイル: flippolicy.py プロジェクト: esperanc/pyprocessing
class FBOWindow(PyprocessingWindow):
    """This is a pyglet window where drawing in fact occurs inside an FBO.
    The flip method is overridden so that instead of merely swapping the
    back and front buffers, the FBO is first blitted onto the back buffer.
    The idea is to provide a stable drawing canvas which is not erased or
    corrupted by the flip."""
    
    def __init__(self, *args, **keyargs):
        """Constructor"""
        # construct the base class
        super(FBOWindow, self).__init__(*args, **keyargs)
        # construct the fbo and attach it
        self.fbo = FBO(self.width, self.height)
        self.fbo.attach()
        
    def flip(self):
        """Override the flip method."""
        # cease using the FBO and start using the regular frame buffer
        self.fbo.detach()
        # save the OpenGL state
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glPushAttrib(GL_ALL_ATTRIB_BITS)
        glViewport(0,0,self.width,self.height)
        # Draws a quad with the fbo as a texture
        glDisable(GL_BLEND)
        glDisable(GL_DEPTH_TEST)
        glDisable(GL_LIGHTING)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
        glEnable(GL_TEXTURE_2D)
        glColor3f(1,1,1)
        glBindTexture(GL_TEXTURE_2D, self.fbo.img)
        glBegin(GL_QUADS)
        for v,t in [((-1,-1,0),(0,0)),
                ((-1,1,0),(0,1)),
                ((1,1,0),(1,1)),
                ((1,-1,0),(1,0))]: 
           glTexCoord2f(*t)
           glVertex3f(*v)
        glEnd()
        # restore the state
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        glPopAttrib()

        # do the actual flip
        super (FBOWindow, self).flip()
        # reattach the fbo for further drawing
        self.fbo.attach()
        
    def on_resize(self,w,h):
        super (FBOWindow, self).on_resize(w,h)
        self.fbo.detach()
        self.fbo = FBO(w,h)
        self.fbo.attach()