I'm trying to achieve proper animation using SDL. Used flags are SDL_HWSURFACE and SDL_DOUBLEBUF.

That what I'm getting is technically smooth (I think), but I can figure out what should I do to remove that trail? My animation is time-based (I'm calculating displacement with delta time).

Link to to video: https://vimeo.com/62065078

my (every-frame) drawing function is like:

for(int x = 0; x < screen->w; ++x)
    for(int y = 0; y < screen->h; ++y)
        draw_pixel(screen, x, y, 136, 136, 136);

and ball:

filledCircleColor(screen, ball.x, ball.y, 17, 0x000000ff);

and finally:


main loop is:

for(;;) {
    curr_ts = stopwatch_seconds_elapsed(sw);
    d_time = curr_ts - prev_ts;
    prev_ts = curr_ts;
    cpSpaceStep(space, d_time);
  • \$\begingroup\$ You may need a higher speed display matrix :p (or more durable eyes) \$\endgroup\$ – user1306322 Mar 18 '13 at 12:03
  • \$\begingroup\$ I think I understand what you are getting at but if you could be clearer with what problem you are trying to solve, specifically what you don't like about the animation that would help. You'll want to update the title and the body of the question accordingly. \$\endgroup\$ – SpartanDonut Mar 18 '13 at 12:09
  • \$\begingroup\$ how are you clearing? \$\endgroup\$ – t123 Mar 18 '13 at 13:16
  • 2
    \$\begingroup\$ Try stepping through the render loop one frame at a time to verify you are actually getting the trails, and it isn't simply an anomaly associated with human eyeballs. If you are still getting the trails, then it is likely because the buffer isn't being properly cleared after each frame. \$\endgroup\$ – Evan Mar 18 '13 at 13:49
  • \$\begingroup\$ Evan: Animation snapshot doesn't contain trail. \$\endgroup\$ – jacekmigacz Mar 18 '13 at 14:22

It looks like what you're seeing is a persistence of vision effect. Your circle isn't really leaving a trail, but it looks like it is because it has a very hard edge. If you use a less contrasting image, or just squint, you will probably see that your image doesn't have the trail.

If you want to fix the app so it doesn't look like it has a trail, your best bet is to ensure you are getting a high framerate, or add a bit of fake motion blur so it counters the jagging effect created by your eyes trying to track the object.

  • \$\begingroup\$ If you want to be able to tell for sure if it's the program or your eyes, take a screenshot or pause the program when the trail is visible. If it was visible with your eyes but not on the image on screen then it's persistence of vision. \$\endgroup\$ – Lunin Mar 18 '13 at 17:48
  • \$\begingroup\$ Also, rendering an anti-aliased version should remove the "hard edge" aspects of the rendering. \$\endgroup\$ – Mokosha Mar 18 '13 at 17:59
  • \$\begingroup\$ anti-aliasing won't decrease the high frequency enough to fix this effect unfortunately, otherwise I wouldn't have seen this effect on my moving text. My experience is, if you're moving something around fast enough in 2D, there's not much you can do other than a bit of motion blur to offset eye tracking issues. \$\endgroup\$ – Richard Fabian Apr 3 '13 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.