Hi Guys,
I want to make a cool invincibility power up effect for a game I am working on, It is all 2d, rendered with opengl, using sprite sheets…
the main character for the game is a bright red crab, and I would like to make him blink white when the user is using the invincibility power up… the sprite sheet is quite large already so having a secondary sprite sheet with the crab white is not really an option… I have played a bit with setting the color in opengl via gl.glColor4f(1,1,1,1); and was wondering is there a color combination that would allow me to render the crab white(perhaps if the rgb value of the crab was already known?)? or is there another way I should go about implementing this?
Thanks
As you’re using OpenGL, you should use a fragment shader, where you can manipulate all colors. In your case you’d simply add RGB(0,1,1) to your crab.
A fixed function approach:
//set environment mode to ADD
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
glColor4f(1f, 1f, 1f, 1f);
//draw the sprite; the colors will be white but the alpha will be in tact
image.draw(50, 50);
//reset mode to default...
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Turn the problem around! Make the original crab image white and use glColor() to make it red! Definitely the easiest approach.
Yeah, that was my first idea too, then I thought the crab was probably not 100% RGB(*,0,0)
Why does that matter?
Because then you cannot make the crab white (well, greyscale) as you’d be losing information, that cannot be added back later.
Thanks for all the info, I ended up using davedes’s approach, and it works great… I can make the crab blink any color now!