/usr/share/doc/python-glitch/examples/blur.py is in python-glitch 0.6-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import glitch, glitch.glut
import glitch.PIL.image as image
import OpenGL.GL.shaders as shaders
class HorizontalBlur(glitch.Shader):
vertex = """
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
"""
fragment = """
uniform sampler2D tex;
uniform int width;
uniform int height;
void main ()
{
float tx = gl_TexCoord[0].x;
float ty = gl_TexCoord[0].y;
float step = 1.0 / float(width);
gl_FragColor =
0.05 * texture2D(tex, vec2(tx - 4.0 * step, ty)) +
0.09 * texture2D(tex, vec2(tx - 3.0 * step, ty)) +
0.12 * texture2D(tex, vec2(tx - 2.0 * step, ty)) +
0.15 * texture2D(tex, vec2(tx - 1.0 * step, ty)) +
0.16 * texture2D(tex, vec2(tx - 0.0 * step, ty)) +
0.15 * texture2D(tex, vec2(tx + 1.0 * step, ty)) +
0.12 * texture2D(tex, vec2(tx + 2.0 * step, ty)) +
0.09 * texture2D(tex, vec2(tx + 3.0 * step, ty)) +
0.05 * texture2D(tex, vec2(tx + 4.0 * step, ty));
}
"""
def set_uniforms(self, ctx, shader):
# XXX: Assumes texture unit 0.
loc = shaders.glGetUniformLocation(shader, 'tex')
shaders.glUniform1i(loc, 0)
(w, h) = ctx['texture_size']
loc = shaders.glGetUniformLocation(shader, 'width')
shaders.glUniform1i(loc, w)
loc = shaders.glGetUniformLocation(shader, 'height')
shaders.glUniform1i(loc, h)
if __name__ == '__main__':
import sys
texture = image.ImageTexture.from_file(sys.argv[1])
camera = glitch.glut.GLUTCamera(eye=[0, 0, 1], children=[
glitch.Translate(-0.5, -0.5, children=[
glitch.ApplyTexture(texture, children=[
HorizontalBlur(children=[
glitch.TexturedRectangle()])])])])
camera.run()
|