Making a sprite flash white.

Started by
18 comments, last by GameDev.net 19 years, 7 months ago
A stencil buffer approach will be quick enough provided you do it right, but will still require a stencil buffer. :P

Possibly you could do something clever with glPixelMapusv()? Set up some pixel maps to map all values of red to FF, and the same for green and blue, but leave alpha untouched?
Advertisement
Or you can just render the sprite twice:
1)Disable color writing, render sprite only in the z-buffer
2)Enable color writing, disable z-writing, set depth func to GL_EQUAL, and render the sprite as a white quad.
I'm not sure though this is 100% correct all the time.

Another alternative would be to use env_add and set the color to (1,1,1,1).
That would set the RGB components to 1(clamping) and the alpha values remain the same.
Mikeman's second idea sounds like a winner, even if it does use an extension. The first one will work if you're using alpha testing but since you're alpha-blending, the transparent pixels are still (I think) drawn to the z-buffer.
I recently had the same problem and I did this:
(I'm using this on my spaceships when they're damaged)

glColor4ub(255,255,255,255);
glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
render your sprite

It's not perfectly white, but I actually like the result more than plain white (it's just making it brighter). You can also try to render the sprite more than 1 times to make it even more brighter.
Quote:Original post by fractoid
Mikeman's second idea sounds like a winner, even if it does use an extension. The first one will work if you're using alpha testing but since you're alpha-blending, the transparent pixels are still (I think) drawn to the z-buffer.


That sounds like it would be what I am looking for, could you elaborate please. I haven’t seen this ENV_ADD before.

One Idea I had is to give the material a very strong specular quality with a white color and shine a light on it. Since the light values are added and then clamped to one this should get me all white providing the light is at the correct angle of course. Which presents the problem of figuring where to position the light source, since I am using orthogonal projection I think this could be tricky.
Quote:Original post by Grain
That sounds like it would be what I am looking for, could you elaborate please. I haven’t seen this ENV_ADD before.


You just set the texture environment to GL_ADD, instead of GL_MODULATE or whatever you're using.

What function am I passing these enums to? I've never seen them before.
glTexEnvf().

And I was wrong about it being an extension, seems it's core OpenGL... dammit, I'm getting rusty on this stuff. :P
A question. . . If you use something like glColor3f(255.0f,255.0f,255.0f), will it multiply the color by 255 and clamp to 1? That would leave black pixels black, though.
Quote:Original post by fractoid
glTexEnvf().

And I was wrong about it being an extension, seems it's core OpenGL... dammit, I'm getting rusty on this stuff. :P


That worked. It took some fiddling though.

This topic is closed to new replies.

Advertisement