Jump to content
  • Advertisement
Sign in to follow this  
samuraicrow

Palette cycling on SDL window?

This topic is 4496 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)
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.

Share this post


Link to post
Share on other sites
Advertisement
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!