#experimental mozaic

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from effect import *
from core import FBO, GLSLShader
from math import cos

class Mosaic(Effect):

    def __init__(self, screenDim):
        self._bufferDim = (32,32)
        self._screenDim = screenDim
        self._backCopy = FBO(*self._screenDim)
        self._lowresCopy = FBO(*self._bufferDim)


    def draw(self, time, delta, start, stop):
    
        # settping transforms
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity();
        glOrtho(0,1,0,1,0.1,1000)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity();
        glTranslatef(0,0,-70)

        # disable z-buffering
        glDisable(GL_DEPTH_TEST)


        self._backCopy.bindAsTexture()
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP)
        
        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, self._screenDim[0], self._screenDim[1])


        self._lowresCopy.bindAsRenderTarget()
        
        glEnable(GL_TEXTURE_2D)

        self.drawQuad()


        glDisable(GL_TEXTURE_2D)
        self._lowresCopy.unbindAsRenderTarget()
        self._lowresCopy.bindAsTexture()

        self.drawQuad()
        
        glBindTexture(GL_TEXTURE_2D, 0)
        
        



    
