How to call :OGL Convolution Filter

BlitzMax Forums/OpenGL Module/How to call :OGL Convolution Filter

Panno(Posted 2008) [#1]
in the german forum a user ask :

how to call the ogl Convolution Filter .

bmax :

filter:Float[] = [0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067, 0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292, 0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117, 0.00038771, 0.01330373, 0.11098164, 0.22508352, 0.11098164, 0.01330373, 0.00038771, 0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117, 0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292, 0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067]

size:int = int(sqr(filter.length))

glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE4, size, size, GL_LUMINANCE, GL_FLOAT, filter)

can anybody help ?

imho filter must be a pointer but i allways have an memory error


fredborg(Posted 2008) [#2]
Probably like this:
glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE4, size, size, GL_LUMINANCE, GL_FLOAT, varptr(filter[0]) )


Panno(Posted 2008) [#3]
sorry but no


ImaginaryHuman(Posted 2008) [#4]
Presumably you've set up the required extension prior to calling glConvolutionFilter?


fredborg(Posted 2008) [#5]
Maybe your graphics card does not support it?

This works fine for me:
SuperStrict

GLGraphics(640,480)
glewinit()

'
' Check if convolution is supported
Local extensions:String = String.FromCString(Byte Ptr(glGetString(GL_EXTENSIONS))).Replace(" ","~n")
If extensions.Contains( "GL_ARB_imaging" ) = False
	Print "GL_ARB_imaging not available"
	End
EndIf
If glConvolutionFilter2D = Null
	Print "glConvolutionFilter2D not available!"
	End
EndIf

'
' Load a pixmap
Local p:TPixmap = LoadPixmap("C:\blitzmax\samples\breakout\media\b-max.png")

'
' Setup convolution filter
Local filter:Float[] = [0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067, 0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292, 0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117, 0.00038771, 0.01330373, 0.11098164, 0.22508352, 0.11098164, 0.01330373, 0.00038771, 0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117, 0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292, 0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067]
Local size:Int = Int(Sqr(filter.length))
glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE, size, size, GL_LUMINANCE, GL_FLOAT, Varptr(filter[0]) )
glEnable( GL_CONVOLUTION_2D )

'
' Setup view matrix
glOrtho 0,640,480,0,-1,1

'
' Draw the pixmap
glpixelzoom 1.0,-1.0
glRasterPos2i 0,0
glBitmap 0,0,0,0,0,0,Null
glPixelStorei GL_UNPACK_ROW_LENGTH, p.pitch Shr 2
glDrawPixels p.width,p.height,GL_RGBA,GL_UNSIGNED_BYTE,p.pixels
		
Flip

WaitKey()

End



plash(Posted 2008) [#6]
"GL_ARB_imaging not available". bingo?