How do you fellows do screen transitions in your programs?
My solution, which I don't particularly like, because it upsets the heirarchy of my code, is to have a fade() function which has direct access to the timer, and to call it where needed.
Oh, even worse actually sometimes, it seems my fade function in
Mirror Stage makes its own timer!
void fadetoblack(bool fade)
{
Timer fps;
glClearColor(0, 0, 0, 1);
for (float alpha = 0; alpha <= 1; alpha += 0.03)
{
if (fade)
setvolume(1 - alpha);
fps.start();
glDisable(GL_BLEND);
glReadBuffer(GL_FRONT);
glDrawBuffer(GL_BACK);
glCopyPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR);
glEnable(GL_BLEND);
while (SDL_PollEvent(&event))
{
//Gobble up all events while fading
}
glLoadIdentity();
glColor4f(0, 0, 0, alpha);
glBegin(GL_QUADS);
glVertex2f(-3, -3);
glVertex2f(-3, 3);
glVertex2f(3, 3);
glVertex2f(3, -3);
glEnd();
if (fps.get_ticks() < 1000 / FRAMES_PER_SECOND)
{
SDL_Delay((1000 / FRAMES_PER_SECOND) - fps.get_ticks());
}
SDL_GL_SwapBuffers();
}
}
This is, I'm sure people will agree, quite a
violent way of doing things.
The other easy alternative would be to have a int somewhere which, if greater than zero, would effect a transition. I'm not a fan of cluttering stuff up with conditional statements (though I do it more than I am comfortable with).