I've written a small sound player utility using SDL and SDL_Mixer. I want to make a small palette cycle animation so I can get familiarized with the APIs in time to start my next porting job.
The program I'm going to be porting is written in C with a macro library to make the curly braces go away. It makes it look more like Basic but I think you can figure out what's going on.
Here's how I'm setting the palette up:
// set the palette entries for color cycling
void CalculatePalette(int frame)
FUNCTION
int shade,temp;
FOR (shade=256; shade>0; shade--) DO
temp=(shade+frame)AND 255;
colors[shade].r=temp;
colors[shade].g=temp;
colors[shade].b=temp;
NEXT
SDL_SetColors(screen,colors,0,256);
END_FUNCTION
And here's how it gets sent to the window in the event loop:
CalculatePalette((unsigned int)colorcount);
color=SDL_SetPalette(screen,SDL_LOGPAL|SDL_PHYSPAL,colors,0,256);
colorcount++;
IF (SDL_Flip < 0) THEN
fprintf(stderr, "error in page flipping\n");
done=TRUE;
END_IF
SDL_Delay(0); // let the multitasking work properly
The problem is that the contents of the window stays black even though it should have shades of grey pulsating through the design.
-edit-
Here's how the window is allocated at the beginning:
/* Set video mode to open window */
screen = SDL_SetVideoMode (512, 8, 8, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWPALETTE);
IF (screen == NULL) THEN
fprintf(stderr,"SDL_SetVideoMode: %s\n", SDL_GetError);
exit(3);
END_IF
Do you think I should be using some other flags on opening the window? I know it should have to be blitted to the display (which is 32-bit true color) but I don't know how I should set up my window any differently.