GLSL Issue
in
Programming Questions
•
9 months ago
I'm struggling with writing a blur filter with a variable radius in GLSL. It was working fine, and then mysteriously stopped working a few days ago. I must have changed something small, but can't remember it, and now I just can't get it to work again. Specifically, when I try to run it, it says "OpenGL error 1282 at top endDraw(): invalid operation"
On the processing side of things, I am using the code from the blur example, only slightly modified:
- /**
- * Blur Filter
- *
- * Change the default shader to apply a simple, custom blur filter.
- *
- * Press the mouse to switch between the custom and default shader.
- */
- PShader blur;
- void setup() {
- size(640, 360, P2D);
- blur = loadShader("blur2.glsl");
- stroke(255, 0, 0);
- rectMode(CENTER);
- }
- void draw() {
- blur.set("radius",3);
- filter(blur);
- rect(mouseX, mouseY, 150, 150);
- ellipse(mouseX, mouseY, 100, 100);
- }
And here is the GLSL code:
- #ifdef GL_ES
- precision mediump float;
- precision mediump int;
- #endif
- uniform sampler2D textureSampler;
- uniform vec2 texcoordOffset;
- uniform float radius;
- varying vec4 vertColor;
- varying vec4 vertTexcoord;
- void main(void) {
- vec4 sum = vec4(0.0);
- float xC=vertTexcoord.x;
- float yC=vertTexcoord.y;
- float count=0.0;
- for(float x=-radius;x<=radius;x++){
- for(float y=-radius;y<=radius;y++){
- sum += texture2D(textureSampler, vec2(xC+x,yC+y));
- count+=1.0;
- }
- }
- sum/=count;
- gl_FragColor = vec4(sum.rgb, 1.0);
- }
Also, in case this is significant, I am currently using Processing 2.0b6.
Thank you for any help you could offer!
1