Unexpected error

This is a code from martinsh but I m getting a weird error on the line 24 (bgl.glReadPixels(x, y, 1, 1, bgl.GL_DEPTH_COMPONENT, bgl.GL_FLOAT, pixels)) and I dont understand why I changed the other errors that I was receiving but this one I dont know how to fix.

I was trying to use this fro blender 2.5x

Console gives me this messa integer argument expected, got float

import GameLogic as G
import bgl
import Rasterizer as R
from bge import logic
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

pixels = bgl.Buffer(bgl.GL_FLOAT, [1])

bgl.glReadPixels(x, y, 1, 1, bgl.GL_DEPTH_COMPONENT, bgl.GL_FLOAT, pixels)

avgPixels = pixels[0]
#Slow adaptation
own.focus = (own.focus0.95 + avgPixels0.05)
avgPixels = own.focus

that means that pixels needs to be an int i guess, try this:

pixels = int(pixels)

add this after the: pixels = bgl…

Dont mean to be annoying but shouldn’t it be un-expected? :slight_smile: Just some constructive criticism? :wink:

I dont know, if this help me solve my problem yes if no please spare your words if you take a look on the keyboard you see that the i is very close the the U so probably you think about this right? just a construtive tought! But i ll put an U there

noise_dof_focus (1).blend (771 KB)
here is the blend from the link, with auto focus

Thanks a lot agoose!!!