Results 1 to 6 of 6

Thread: Creating motion trails with glCopyTexSubImage2D

  1. #1
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    3

    Creating motion trails with glCopyTexSubImage2D

    Hi, basically what I want to do is draw my scene, copy it to a texture, and then draw the texture before I draw the scene the next time. Basically what I want to do is create motion trails behind my objects. Here's my code:

    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glBegin(GL_QUADS);
    glColor4f(1.f, 1.f, 1.f, 0.97f);
    glTexCoord2f(0.0, 1.0); glVertex2f(0.f, windowH-textureSize);
    glTexCoord2f(0.0, 0.0); glVertex2f(0.f, windowH);
    glTexCoord2f(1.0, 0.0); glVertex2f(textureSize, windowH);
    glTexCoord2f(1.0, 1.0); glVertex2f(textureSize, windowH-textureSize);
    glEnd();

    // draw some spheres or whatever
    drawScene();

    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, windowW, windowH);


    This mostly works, but if I set the alpha value high (you'll notice it's at .97 above), the trails don't fade out all the way to black. They sort of fade to a dark grey. Obviously I want them to disappear completely after a second or so.

    I can't for the life of me figure out why this happens. Here's a magnified screenshot:

    http://www.mat.ucsb.edu/~e.newman/trails.jpg

    I've got a GeForce 7800GT on WinXP.

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Creating motion trails with glCopyTexSubImage2D

    Colors get rounded to the nearest value before writting to framebuffer.
    round(16 * 97%) = round(15,52) = 16

    Source:
    http://www.opengl.org/documentation/spec...000000000000000

    And by the way - if you blend your texture with framebuffer using alpha=0.97 then you get additional 3% of previous framebuffer content added to you final color.

  3. #3
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    3

    Re: Creating motion trails with glCopyTexSubImage2D

    ok, so is there any way around that? or what would be your recommended way for creating motion trails?

  4. #4
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Creating motion trails with glCopyTexSubImage2D

    You can paint that texture multiple times - every time using alpha = 0.5. Painted 2 times gives 75%, 3 times gives 87,5%, and so on.
    However, you will pay for this with increased datarate.
    You could also use a very simple fragment shader if that's not a problem.

  5. #5
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    3

    Re: Creating motion trails with glCopyTexSubImage2D

    The multiple texturing with .5 alpha doesn't work - it obscures the trails completely (they're gone after only a few frames). I want them to last for 60 frames or even longer. So I settled on using a shader which works fine on my desktop but my laptop doesn't support it. Oh well.

  6. #6
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Creating motion trails with glCopyTexSubImage2D

    Let's try completely different approach...

    Step 1:
    glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_ZERO);
    -now render texture that's behind your scene

    Step 2:
    glBlendFunc(GL_ONE, GL_ONE);
    glColor3ub(1, 1, 1);
    -draw fullscreen quad (no texture)

    Step 3:
    glCopyTexSubImage2D(...); //copy framebuffer to your texture

    Step 4:
    glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_ZERO);
    -now render texture that's behind your scene

    Step 5:
    -now render scene

    Step 6:
    glCopyTexSubImage2D(...); //copy framebuffer to your texture

    As you can see I inverse the texture 2 times - when it's iversed I can use blending to add (1,1,1) to inversed texture wchich is eqivalent to adding (-1, -1, -1) to normal texture

Similar Threads

  1. Motion blur/swipe trails with accumulation buffer
    By ChucklesDarling in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-20-2014, 11:20 AM
  2. 32 bit value with glCopyTexSubImage2D
    By jos_t_tarigan in forum OpenGL: GLSL
    Replies: 2
    Last Post: 01-25-2011, 04:31 AM
  3. Glow / blur / trails ?
    By Selfdestroyer in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-14-2007, 03:21 AM
  4. Explosions smoke and trails on nv35
    By Roman Grigoriev in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 09-04-2003, 04:53 AM
  5. Particle Trails
    By TheMyriad in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-26-2003, 03:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean