Advertisement Jump to content
Sign in to follow this  

Palette cycling on SDL window?

This topic is 4588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)
  int shade,temp;
  FOR (shade=256; shade>0; shade--) DO
      temp=(shade+frame)AND 255;

And here's how it gets sent to the window in the event loop:
            CalculatePalette((unsigned int)colorcount);
            IF (SDL_Flip < 0) THEN
                fprintf(stderr, "error in page flipping\n");
            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);

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.

Share this post

Link to post
Share on other sites
I dont know if this is part of your "different" programming macro style, but SDL_Flip() takes an argument, and that argument is usually your screen surface taht you want to flip.

Share this post

Link to post
Share on other sites
After having tested sdlBasic's color-cycling demo and having read in the comments in that demo that it doesn't work in a window and requires having X reset in Linux, I'm going to have to find another way to do the animation.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!