Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Render onto previous frame with blending

  1. #1
    Intern Contributor
    Join Date
    Apr 2007
    Location
    Ohio
    Posts
    58

    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.
    Last edited by paradoxresolved; 02-03-2014 at 11:34 AM. Reason: forgot the OpenGl version number.

  2. #2
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    78
    A relative beginner after seven years of membership? What have you been doing lately?

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

    Code :
    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...

  3. #3
    Intern Contributor
    Join Date
    Apr 2007
    Location
    Ohio
    Posts
    58
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •