Render onto previous frame with blending

Hello all,

I’m a relative beginner, but I’ve created a simple program where I’d like to render each additional frame onto the previous frame, ignoring the color black and all other colors are blended at, say, 30%. In other words, each frame leaves a ghost behind for every color but black. I’ve been doing some reading about shaders, but as of yet I do not quite understand them. Can anyone point me in the simplest direction to accomplish this task?

I would appreciate the help. Thanks!

EDIT: I’m using OpenGL v 2.0, Visual C++ 2010 and Windows 7.

A relative beginner after seven years of membership? What have you been doing lately? :wink:

I’m not sure whether this is possible even without shaders, but since you ask for them, here you go:

layout(location = 0) in vec2 position;
layout(location = 1) in vec2 texCoord;
out vec2 texCoordFrag;

void main()
	texCoordFrag = texCoord;
	gl_Position = position;

uniform sampler2D colorSampler;
in vec2 texCoordFrag;
out vec4 color;

void main()
	color = texture(colorSampler, texCoordFrag) * vec4(1.0f, 1.0f, 1.0f, 0.3f); 

The above shader draws the content from the texture (ideally containing the last frame) onto the active frame, at a transparency of 30% (maybe you have to save the active frame in a texture as well). If you don’t clear what you’ve drawn before, you should get the desired result. If you want black to be ignored, you can add an if clause to the shader code (though bad for performance, I guess).
Of course, the whole environment with shaders, vertex buffer objects and so on must be created before…

Cool! Thanks! That should give me a place to start.

Started the account a long time ago, then was pulled away from OpenGL for a while. . . It’s changed a bit. Thanks again! :slight_smile: