Quick question here:
If I were drawing a moving starfield and I knew exactly where
pixels had changed, would it be smarter to use SDL_UpdateRect() on just
those parts, in a loop (so it would have to be called a few hundred
times before the loop is over), or, would it just be smarter to use
SDL_Flip() when the loop is done?
ex:
for (i = 0; i < NUM_STAR; i++) {
draw_star(x, y, color);
SDL_UpdateRect(screen, x, y, x, y);
}
or
for (i = 0; i < NUM_STAR; i++) {
draw_star(x, y, color);
}
SDL_Flip(screen);
Quick question here:
If I were drawing a moving starfield and I knew exactly where
pixels had changed, would it be smarter to use SDL_UpdateRect() on just
those parts, in a loop (so it would have to be called a few hundred
times before the loop is over), or, would it just be smarter to use
SDL_Flip() when the loop is done?
ex:
for (i = 0; i < NUM_STAR; i++) {
draw_star(x, y, color);
SDL_UpdateRect(screen, x, y, x, y);
}
or
for (i = 0; i < NUM_STAR; i++) {
draw_star(x, y, color);
}
SDL_Flip(screen);
It depends on how many rectangle updates you’re doing. I’m not sure exactly
where the threshold is, so do some testing, but after some number of rects
it’s just better to flip. The exact threshold depends on the hardware
configuration, but a starfield is probably a good candidate for a flip.
See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment