Sign in to follow this  
Grain

Making a sprite flash white.

Recommended Posts

Grain    500
What would be the best way to get a textured quad to briefly flash white. I am using the GL_RGBA pixel format and basically what I want is to momentarily change the R G and B values to 1.0. The obvious and brute force way is to manually step through the pixel array and set each individual byte, render and then restore them to their original values. But that would probably be extremely slow and since I am using texture objects I don’t actually have the image saved in memory anywhere. SO, I was thinking there could be some way of doing it by playing with the blending function or lighting and materials.

Share this post


Link to post
Share on other sites
nts    968
not sure what you are asking, info you are giving but

glColor3f(r, g, b);
glColor4f(r, g, b, a);

disable your color arrays, if u were using them...

Share this post


Link to post
Share on other sites
Grain    500
Ok here is my function to render a sprite.



void Sprite::Render(GLuint TexHndl)
{
glBindTexture(GL_TEXTURE_2D, TexHndl);
glPushMatrix();
glTranslatef((int)Pos.x,(int)Pos.y,0.0f);
glRotatef(angel,0,0,1);
glScalef(size,size,1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f); glVertex2f(-w/2.0f,- h/2.0f);
glTexCoord2f(1.0f,0.0f); glVertex2f(w/2.0f,-h/2.0f);
glTexCoord2f(1.0f,1.0f); glVertex2f(w/2.0f,h/2.0f);
glTexCoord2f(0.0f,1.0f); glVertex2f(-w/2.0f,h/2.0f);
glEnd();
glPopMatrix();
}

What I want is to instead of using the RGB values I get from glBindTexture(GL_TEXTURE_2D, TexHndl), to use pure white to draw the sprite, but I want to still use the Alpha values from glBindTexture(GL_TEXTURE_2D, TexHndl).

Share this post


Link to post
Share on other sites
nts    968
you can try using blending with something like GL_SRC_ALPHA and GL_ONE as the blending function (glBlendFunc(src, dst), glEnable(GL_BLEND), etc) not sure if that does the trick though.

Share this post


Link to post
Share on other sites
iliak    278
Why not disabling texture and drawing all in white ?

glDisable(GL_TEXTURE_2D);
glColor3f(1.0, 1.0, 1.0);
// Dont forget to disable lighting too

..... draw your mesh here....


glEnable(GL_TEXTURE_2D),

Share this post


Link to post
Share on other sites
Grain    500
Quote:
Original post by nts
you can try using blending with something like GL_SRC_ALPHA and GL_ONE as the blending function (glBlendFunc(src, dst), glEnable(GL_BLEND), etc) not sure if that does the trick though.
Gave me transparent Sprites.

Quote:
Original post by iliak
Why not disabling texture and drawing all in white ?
This gives me a white square.

Quote:
Original post by grekster
Swap the sprite your drawing with just a plain white sprite?
I have over a hundred Sprites It’s just not feasible to make white versions of each one. Plus I would like to extent the ability to use other colors as well.

Share this post


Link to post
Share on other sites
CRACK123    235
Quote:
Original post by Grain

I have over a hundred Sprites It’s just not feasible to make white versions of each one. Plus I would like to extent the ability to use other colors as well.


Actually you have to make only one and you can use GL_REPEAT and it will be seamless.

Share this post


Link to post
Share on other sites
fractoid    703
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?

Share this post


Link to post
Share on other sites
mikeman    2942
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.

Share this post


Link to post
Share on other sites
fractoid    703
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.

Share this post


Link to post
Share on other sites
amannis    146
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.

Share this post


Link to post
Share on other sites
Grain    500
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.

Share this post


Link to post
Share on other sites
mikeman    2942
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.

Share this post


Link to post
Share on other sites
nagromo    676
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

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