SDL_FillRect and MapRGB concerns

Hello everyone,

Why does this not work in my loop? In an earlier loop where I set everything up, I set up r[127], g[127] and b[127] to random shades of either gray or red. Then, this code in the next loop:

Code:
SDL_FillRect(screen, &explo_rect, SDL_MapRGB( screen->format,r[i],g[i],b[i]));

produces all kinds of colors. In fact, when I set all the values to 100 it still does that. I could manually call the function within the loop to just a few shades, but ideally I would prefer 128 shades of dark/medium red and gray.

Here is a doctored (yanked) snippet from the previous loop:

Code:
for(which_one=0;which_one<123;which_one++)
{
if(rand()%2 == 0)
{
r[which_one] = rand()%128;
g[which_one] = b[which_one] = r[which_one];
}
else
{
r[which_one] = rand()%128;
g[which_one] = 0;
b[which_one] = 0;
}
}

Are you updating explo_rect? Is i (not which_one) the correct
counter? Are you calling SDL_UpdateRect()? Are you calling
SDL_PumpEvents() or other event functions to feed SDL paint events?

:smiley: Well, the problem was my definition of the struct way at the top of main.cpp that held the xs and ys. I forgot to update it from 63 to 126, the new amount, but now everything’s peachy. That said, sdl_pumpevents and sdl_updaterect, I’ve never used them so far but my programs have alwaysl worked. Is that because the main loop has a sdl_pollevents? Or is it just because of the double buffering and page flipping? Perhaps at least sdl_updaterect might be useful if the program was being run on someone else’s computer so it’s a portability thing.

SDL_Flip() calls SDL_UpdateRect() and SDL_PollEvent() calls
SDL_PumpEvents() so you’re fine.On 27/05/2010, bala_48225 <bala_48225 at yahoo.com> wrote:

:smiley: Well, the problem was my definition of the struct way at the top of
main.cpp that held the xs and ys. I forgot to update it from 63 to 126, the
new amount, but now everything’s peachy. That said, sdl_pumpevents and
sdl_updaterect, I’ve never used them so far but my programs have alwaysl
worked. Is that because the main loop has a sdl_pollevents? Or is it just
because of the double buffering and page flipping? Perhaps at least
sdl_updaterect might be useful if the program was being run on someone
else’s computer so it’s a portability thing.

thanks, it works even without pumpevents or pollevents(it’s a separate explosion loop at the end of the game for whichever duelist gets blown up) but I left pumpevents in there just in case with a comment suggesting that it might be necessary for portability to other people’s PCs or whatnot. :smiley: