Hi!
I need to blur a texture using ZenGL. It does not need to be very fast because I need to blur it once and I will use it for several frames (I want to blur everything bellow a Game Dialog).
Andrey converted this code of a BoxBlur to me, it works very well, but it does have two side-effects!
- To works well I need to use it twice (or the blur will be very weak).
- The blurred image seems to be some pixels off, so I get a strange effect, it seems the background was moved.
Code:
procedure BoxBlur(var Texture: zglPTexture);
var
X, Y: Integer;
yLine, xLine: PByteArray;
data : PByteArray;
realWidth : Integer;
realHeight : Integer;
begin
realWidth := Round( Texture.Width / Texture.U );
realHeight := Round( Texture.Height / Texture.V );
tex_GetData(Texture, data);
for Y := 1 to realHeight - 2 do
begin
yLine := @data[ realWidth * ( Y - 1 ) * 4 ];
xLine := @data[ realWidth * Y * 4 ];
for X := 1 to realWidth - 2 do
begin
xLine^[X * 4 ] := (xLine^[X * 4 - 4] + xLine^[X * 4 + 4] + yLine^[X * 4 - 4] + yLine^[X * 4 + 4] + yLine^[X * 4 ] + xLine^[X * 4 - 4] + xLine^[X * 4 + 4] + xLine^[X * 4]) div 8;
xLine^[X * 4 + 1] := (xLine^[X * 4 - 3] + xLine^[X * 4 + 5] + yLine^[X * 4 - 3] + yLine^[X * 4 + 5] + yLine^[X * 4 + 1] + xLine^[X * 4 - 3] + xLine^[X * 4 + 5] + xLine^[X * 4 + 1]) div 8;
xLine^[X * 4 + 2] := (xLine^[X * 4 - 2] + xLine^[X * 4 + 6] + yLine^[X * 4 - 2] + yLine^[X * 4 + 6] + yLine^[X * 4 + 2] + xLine^[X * 4 - 2] + xLine^[X * 4 + 6] + xLine^[X * 4 + 2]) div 8;
end;
end;
tex_SetData(Texture, data, 0, 0, realWidth, Texture.Height);
zgl_FreeMem( data );
end;
Anybody have to suggest some alternative blurring routine? A Gaussian Blur seems to be ideal, but I wasn't able to convert it to ZenGL after some tries.
Thanks
Bookmarks