     )
 
   execute: ->
-    Crafty.c 'TextureFilter',
+    Crafty.c 'ImageWithEffects',
+      _repeat: 'repeat'
+      ready: no
+
       init: ->
-        @requires 'WebGL'
-        @bind("Draw", @_drawFiltered)
-        if @has('Image')
-          @unbind("Draw", @_drawImage)
-
-        @textureFilters = []
+        @bind('Draw', @_drawImage)
 
       remove: ->
-        @unbind("Draw", @_drawFiltered)
-
-      _drawFiltered: (e) ->
-        for f in @textureFilters
-          f.draw.call(this, e)
-        @_drawImage(e)
-
-    Crafty.c 'ColorShader',
-      init: ->
-        @requires 'TextureFilter'
-        colorShaderProgram = this.webgl.getProgramWrapper(
-          "ColorShader",
-          COLOR_OVERRIDE_FRAGMENT_SHADER,
-          DEFAULT_TEXTURE_VERTEX_SHADER,
-          COLOR_OVERRIDE_SHADER_ATTRIBUTE_LIST
-        )
-        @textureFilters.push {
-          shader: colorShaderProgram,
-          draw: @_drawColorShader
-        }
-
-      _drawColorShader: (e) ->
-        #e.program.writeVector("aColor",
-            #this._red/255,
-            #this._green/255,
-            #this._blue/255,
-            #this._strength
-        #);
-        #console.log 'foobar', @_red
-
-      remove: ->
+        @unbind('Draw', @_drawImage)
 
       colorShader: (color) ->
         if arguments.length >=3

  uniform mediump vec2 uTextureDimensions;

  void main(void) {
    highp vec2 coord = vTextureCoord.xy / uTextureDimensions;
    mediump vec4 texelColor = texture2D(uSampler, coord);

    gl_FragColor = texelColor;
  }
"""

COLOR_OVERRIDE_SHADER_ATTRIBUTE_LIST = [
  { name: "aPosition", width: 2 },
  { name: "aTextureCoord", width: 2 },
  { name: "aColor", width: 4 }
]


class Game.Scripts.Test extends Game.LazerScript
  metadata:

        @trigger("Invalidate")
        this

      image: (url, repeat) ->
        @__image = url
        @_repeat = repeat || 'no-repeat'
        @img = Crafty.asset(url)
        if !@img
          @img = new Image()
          Crafty.asset url, @img
          @img.src = url
          img.onload = => @_onImageLoad()
        else
          @_onImageLoad()
          @trigger 'Invalidate'
        this

      _onImageLoad: ->
        if @has 'WebGL'
          @_establishShader("imageFx:#{@__image}", IMAGE_EFFECT_FRAGMENT_SHADER, IMAGE_EFFECT_VERTEX_SHADER, IMAGE_EFFECT_ATTRIBUTE_LIST)
          @program.setTexture(@webgl.makeTexture(@__image, @img, (@_repeat isnt 'no-repeat')))

        if @_repeat is 'no-repeat'
          @w = @w || @img.width
          @h = @h || @img.height
        @ready = yes
        @trigger 'Invalidate'

      _drawImage: (e) ->
        if e.type is 'webgl'
          pos = e.pos

          # Write texture coordinates
          e.program.writeVector('aTextureCoord',
             0, 0,
             0, pos._h,
             pos._w, 0,
             pos._w, pos._h
          )


    Crafty.e('2D, WebGL, Image')
      .image('images/horizon-city.png')
      .attr(
