0

In many demoscene productions you can see the effect of flashing white screen when percussion beat happens (https://www.youtube.com/watch?v=2SbGffUzHSs). I have coded such effect and in works fine. Code of fading function (it ie executed in the render() function):

void fade() 
{
glLoadIdentity();                                   
glTranslatef (0.0f, 0.0f, -5.0f);

glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);

glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE); 

if (alpha <= 1)
{
    glColor4f(1.0, 1.0, 1.0, alpha);

    glBegin(GL_QUADS);         
    glVertex3f(-1.0f, -1.0f, 1.0f);
    glVertex3f( 1.0f, -1.0f, 1.0f);
    glVertex3f( 1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glEnd();

    alpha += 0.0025;
}           
else
{
    glColor4f(1.0, 1.0, 1.0, alpha_inv);

    glBegin(GL_QUADS);         
        glVertex3f(-1.0f, -1.0f, 1.0f);
        glVertex3f( 1.0f, -1.0f, 1.0f);
        glVertex3f( 1.0f, 1.0f, 1.0f);
        glVertex3f(-1.0f, 1.0f, 1.0f);
    glEnd();

    alpha_inv -= 0.0025;
}

glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);    

return;
}

I have two issues:

  • I need some kind of parameter for white flash duration control (ie. 1st flash lasts 1 second, 2 flash lasts only 0,25 second)
  • The effect has to have the same speed on each computer (slow and fast).

What can I do in the code above to achieve it?

genpfault
  • 51,148
  • 11
  • 85
  • 139
slowbro
  • 53
  • 5
  • 1
    Yea need an *easing function* that takes t as a parameter. In order to get t you need a *stopwatch*. – Robinson Sep 03 '17 at 10:36
  • @Robinson: What do you mean a stopwatch? What is t parameter? How to calculate parameter t? Could you please clarify? – slowbro Sep 03 '17 at 10:54
  • I gave you some terms to google. – Robinson Sep 03 '17 at 11:01
  • 1
    measuring time is platform dependent On Windows you got performance timers, On PC you got RDTSC but that can be hard to implement properly on mobile HW, you can use system timers but those are usually not accurate, you can have timing thread with `sleep` which is also not very precise nor reliable .... There is also the PIT controller (PC) if OS allows its access ... see [Sprites sequence control through DeltaTime](https://stackoverflow.com/a/41920247/2521214) – Spektre Sep 04 '17 at 08:16
  • Possible duplicate of [Sprites sequence control through DeltaTime](https://stackoverflow.com/questions/41917471/sprites-sequence-control-through-deltatime) – Spektre Sep 04 '17 at 08:23
  • [Good reading for the second bullet point](https://gafferongames.com/post/fix_your_timestep/) – cmourglia Sep 05 '17 at 13:37

0 Answers0