Hello, it’s my first post here so I hope I’ve asked the question in a proper section
I have a strange problem with textures in FBO, but maybe first the code.
Vertex Shader:
varying vec2 coord;
void main(void)
{
coord = gl_Vertex.xy;
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
}
Fragment Shader:
const float PI = 3.141592653589793;
uniform sampler2D tex;
uniform vec2 center;
uniform float radius;
uniform float strength;
varying vec2 coord;
void main(void)
{
vec4 info = texture2D(tex, coord);
float drop = max(0.0, 1.0 - length(center - coord) / radius);
drop = 0.5 - cos(drop * PI) * 0.5;
info.r += drop * strength;
gl_FragColor = info + vec4(drop, drop, drop, 1.0);
}
Program
init
dropFbo.allocate(screenWidth, screenHeight, GL_RGBA);
dropFbo2.allocate(screenWidth, screenHeight, GL_RGBA);
dropShader.load("shaders/drop.vert", "shaders/drop.frag");
dropFbo.begin();
dropPlane.draw();
dropFbo.end();
update on mouse click
dropFbo2.begin();
dropShader.begin();
dropFbo.getTextureReference(0).bind();
dropShader.setUniform2f("center", posX, posY);
dropShader.setUniform1f("radius", radius);
dropShader.setUniform1f("strength", strength);
dropPlane.draw();
dropFbo.getTextureReference(0).unbind();
dropShader.end();
dropFbo2.end();
dropFbo.begin();
dropFbo2.draw(0, 0);
dropFbo.end();
The problem is as follows. When I render my FBO it has only a red circle representing my last click. It should save between clicks and not clean itself. I look through the code and I’m sure I don’t clear the FBO anywhere, I also don’t render anything else to it. It looks like the texture being bind for the shader is always the same, is not getting update. I don’t have any clue why.