Sign in to follow this  
skullfire

OpenGL Color swapping on OGL ES 2

Recommended Posts

Hi all. I am creating a 2D game on OGL ES for iPhone. I want the player to be able to customize his character's color (For example, his character is a dog. He could change his main color to brown, white, etc). Now, lets suppose this is the image of my dog (thanks google images): http://dogs.thefuntimesguide.com/images/free/puppy-dog-face.jpg As you can see, he has different shades of brown, and some parts of the image which will not be colored/tinted (tongue, eyes, teeth, black outline). What is the best way to do this coloring? Is there a way could define a grayscale image (texture?) and add color to this? Ive searched on google, and found this: http://stackoverflow.com/questions/662440/palette-animation-in-opengl "Currently I am doing it with 2 textures: white texture under the other texture, translated the specific pixel color into transparent, then I change white texture color with glColor3f() function to what ever I want, and I see the "palet animation" on that specific color." This seems to be kinda what i want, but will the glColor color the gray's accordingly? I dont have too much experience with OGL, so any help or guidance will be greatly appreciated! :)

Share this post


Link to post
Share on other sites
I think your best approach there would be to use a second image that holds information about which areas are colored. Then you can use a fragment shader to set each fragment's color depending on whether it lies withing the colorable area or not.

Share this post


Link to post
Share on other sites
A fragment shader would be cool, but i think iPhone does not support shaders at the moment :S

AverageJoe, do u mean that i create a mask in photoshop and then render this map with some kind of blending function on ogl? What do u mean?

Share this post


Link to post
Share on other sites
How i generally color things in opengl/directx is have a white (or greyscale) image, and then just set the diffuse color to the color i want.

This works because white is all colors put together so you can easily subtract colors out to get the color you want.

So if you have a grescale dog face, if you set the diffuse color to brown, it will be in shades of brown. If you set it to green, it will be in shades of green, etc.

That technique doesn't work for all situations, but it works nicely for some (:

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