Bring this script to blender 2.53

Someone can help me to translate this script from blender 2.49 to 2.53, im trying here to take a look on the errors on the console window but i coldnt make the changes properly.

import GameLogic as G
import BGL
import Rasterizer as R

scene = G.getCurrentScene()
cont = G.getCurrentController()
objList = scene.objects
own = cont.owner

viewport = BGL.Buffer(BGL.GL_INT, 4)
BGL.glGetIntegerv(BGL.GL_VIEWPORT, viewport);

width = R.getWindowWidth()
height = R.getWindowHeight()

x = viewport[0] + width/2
y = viewport[1] + height/2

x1 = viewport[0] + width/3
y1 = viewport[1] + height/3

x2 = viewport[0] + width/3
y2 = viewport[1] + height/2

x3 = viewport[0] + width/2
y3 = viewport[1] + height/2

x4 = viewport[0] + width/2
y4 = viewport[1] + height/3

pixels = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels1 = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels2 = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels3 = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels4 = BGL.Buffer(BGL.GL_FLOAT, [1])

BGL.glReadPixels(x, y, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels)
BGL.glReadPixels(x1, y1, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels1)
BGL.glReadPixels(x2, y2, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels2)
BGL.glReadPixels(x3, y3, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels3)
BGL.glReadPixels(x4, y4, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels4)

avgPixels = (pixels[0]+pixels1[0]+pixels2[0]+pixels3[0]+pixels4[0])/5.0

#Slow adaptation
own.avgL = (own.avgL0.98 + avgPixels0.02)

avgPixels = own.avgL

I really need this script working soon as possible, sorry for ask you guys sutch a begginer question, but i really need it working.

import GameLogic as G
import bgl as BGL
import Rasterizer as R

scene = G.getCurrentScene()
cont = G.getCurrentController()
objList = scene.objects
own = cont.owner

viewport = BGL.Buffer(BGL.GL_INT, 4)
BGL.glGetIntegerv(BGL.GL_VIEWPORT, viewport);

width = R.getWindowWidth()
height = R.getWindowHeight()

x = int(viewport[0] + width/2)
y = int(viewport[1] + height/2)

x1 = int(viewport[0] + width/3)
y1 = int(viewport[1] + height/3)

x2 = int(viewport[0] + width/3)
y2 = int(viewport[1] + height/2)

x3 = int(viewport[0] + width/2)
y3 = int(viewport[1] + height/2)

x4 = int(viewport[0] + width/2)
y4 = int(viewport[1] + height/3)

pixels = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels1 = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels2 = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels3 = BGL.Buffer(BGL.GL_FLOAT, [1])
pixels4 = BGL.Buffer(BGL.GL_FLOAT, [1])

BGL.glReadPixels(x, y, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels)
BGL.glReadPixels(x1, y1, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels1)
BGL.glReadPixels(x2, y2, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels2)
BGL.glReadPixels(x3, y3, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels3)
BGL.glReadPixels(x4, y4, 1, 1, BGL.GL_LUMINANCE, BGL.GL_FLOAT, pixels4)

avgPixels = (pixels[0]+pixels1[0]+pixels2[0]+pixels3[0]+pixels4[0])/5.0

#Slow adaptation
own["avgL"] = (own["avgL"]*0.98 + avgPixels*0.02)

avgPixels = own["avgL"]

That should work. Had to round the x, y co-ordinates as it only takes integers, change “import BGL” to “import bgl as BGL” as modules like BGL and Mathutils are lower case in 2.5, and change the way the properties were accessed from own.avgL to own[“avgL”]. Seems to be returning the average amount of light on screen, which is a handy script. Would it be ok with you if I kept this script for my own project?

Really thanks for the help, you made my day!
UHUUU!
This script was created for Martinsh, i allways use his scripts, he probably put them on this forum so i think that he shared the filters with us with good will.

Use the script that I showd you with this one here:

uniform sampler2D bgl_LuminanceTexture;
uniform sampler2D bgl_RenderedTexture;
uniform float avgL;
uniform float HDRamount = 0.1;
vec2 texcoord = vec2(gl_TexCoord[0]).st;
void main(void)
{
float contrast = avgL;
float brightness = avgL * HDRamount;

vec4 value = texture2D(bgl_RenderedTexture, texcoord);

gl_FragColor = (value/contrast)-brightness;
}

that ll create a HDRI effect, this is a martinsh filter too