Sign in to follow this  
Maxamor

SDL Palette Swapping / Cycling

Recommended Posts

Maxamor    361
I'm working on an NES-style game (a Mega Man clone) and am looking for a way to cycle the colors of the player when he charges up his weapon (like was possible in Mega Man 4, 5, 6, etc.). Currently my game uses 32-bit surfaces. From what I understand it would be inefficient to actually cycle colors of surfaces in 32-bit mode. (Is this incorrect/a misconception?) In reading about palette-based surfaces, the SDL documentation talks about surfaces having a logical and a physical palette and gives a brief description about each. I have to admit that the explanation is a little too brief for me and I can't make sense of it. Does anyone have any information or sample code working with palette-based surfaces in SDL?

Share this post


Link to post
Share on other sites
samuraicrow    325
Paletted 8-bit modes should be deprecated in SDL. They are so broken that I've never gotten the palette-cycling function to work in a window. It's strictly full-screen and I think it never works on Windows the OS either. It did work on the older Linux version I tried it on though.

You could try making a mask and using per-surface alpha-blending to try to overlay colors on your player instead. That's about the only solution I can think of short of writing a palette shader in OpenGL's GLSL.

Share this post


Link to post
Share on other sites
Maxamor    361
Good to know. I kind of have that feeling, too.

I have my palette-swapping code working somewhat (even in a window, on Windows) but I'm still a bit confused as to utilize the logical and physical palettes effectively.

I had given some consideration to swapping out my SDL-based drawing code and switching to using OpenGL. Problem is I haven't been able to find a good beginner resource for OpenGL that uses the non-deprecated API.

I'm actually very interested in learning how to accomplish this using shaders, and I'm going to research a bit more to see what's involved.

Share this post


Link to post
Share on other sites
samuraicrow    325
A problem with a palette simulation shader is that it requires the whole screen to be paletted to work properly. For a MegaMan clone that should be a given since all of the Nintendo 8-bit games never exceeded 56 or so colors.

The biggest problem I've run into with OpenGL is trying to find a screenmode that will use 8-bit colors in its pixel-buffers. The only suggestions I've heard is to use a 32-bit screenmode with 24-bits unused and use the red channel as the source for the shader and use it to do a CLUT (that's Color Look-Up Table) operation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this