Aramaz
Junior Devvie  
Java Games Rock!
|
 |
«
Posted
2006-01-17 10:27:17 » |
|
How can I change the color of a sprite (texture) to become brighter than it is? I know I can set color but it doesn't get brighter...
I want to make the sprite flash to white and then back to normal again. Do I have to use lightning and stuff or is there an easier way. (It's a 2d game using lwjgl)
|
|
|
|
hvor2
Junior Devvie  
Beyond mind, there is an awareness...
|
 |
«
Reply #1 - Posted
2006-01-17 10:38:12 » |
|
Yes, lightning is one option, with high specularity. But it is position dependant, so maybe it is not the best solution. You can blend your texture with white (GL_ONE), I think that will work.
|
|
|
|
princec
|
 |
«
Reply #2 - Posted
2006-01-17 10:39:03 » |
|
1 2 3 4 5 6 7 8
| if (GLContext.getCapabilities().GL_EXT_secondary_color) { GL11.glEnable(EXTSecondaryColor.GL_COLOR_SUM_EXT); EXTSecondaryColor.glSecondaryColor3ubEXT((byte)255, (byte)255, (byte)255); } GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); |
Works even when GL_EXT_secondary_color is not present but doesn't look nearly as good. If anyone finds a better way than this that doesn't require exotic hardware please let me know! Cas 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Aramaz
Junior Devvie  
Java Games Rock!
|
 |
«
Reply #3 - Posted
2006-01-18 05:58:04 » |
|
1 2 3 4
| if (GLContext.getCapabilities().GL_EXT_secondary_color) { GL11.glEnable(EXTSecondaryColor.GL_COLOR_SUM_EXT); EXTSecondaryColor.glSecondaryColor3ubEXT((byte)255, (byte)255, (byte)255); } |
Good stuff, that is exactly what I need. Is this ability common in graphics card or are there many cards that doesn't support it? Without this capability it basically just blends it to white? What I want to do is to make it flash (growing linearly from original color to white then back again)... so if this GL_EXT_secondary_color does not exist, how wold I do it then? (or should I just count on this existing on most cards)
|
|
|
|
princec
|
 |
«
Reply #4 - Posted
2006-01-18 10:56:49 » |
|
I've not actually come across a machine without this extension yet. But the fallback is simply to use additive blending instead of alpha blending when rendering the sprite which makes it a lot brighter if there's any background image there already but otherwise has no effect on black backgrounds. Cas 
|
|
|
|
Orangy Tang
|
 |
«
Reply #5 - Posted
2006-01-18 12:19:36 » |
|
Yes, lightning is one option, with high specularity.
Ooo, now theres a nice idea. For sprites you should easily be able to fudge the normals so they're pointing straight at the camera, then the specular colour would just be added on top. So even cards without the secondary extension would be able to blend towards a colour rather than just white.
|
|
|
|
princec
|
 |
«
Reply #6 - Posted
2006-01-18 12:21:12 » |
|
Hmm.. I believe that extension is part of the way the separate specular colour is calculated. Without it the specular light component is simply blended with the diffuse component giving, er, remarkably unspecular highlights. But this is also the reason why it is present on every card I've ever seen. Cas 
|
|
|
|
DzzD
|
 |
«
Reply #7 - Posted
2006-01-18 12:30:58 » |
|
Depending on what you want to do, you may convert your texture RGB to HSL increase luminosity(L) and convert it back to RGB
Bruno
|
|
|
|
DzzD
|
 |
«
Reply #8 - Posted
2006-01-18 12:33:30 » |
|
Ps:
You can also keep in memory the two texture not bright and bright and map the brighter one onto the initial texture, alpha used for the brighter texture will determine the luminosity.
Bruno
|
|
|
|
Orangy Tang
|
 |
«
Reply #9 - Posted
2006-01-18 12:36:38 » |
|
I might be reading the specs wrong, but I thought the EXT_separate_specular_color extension introduced a second colour for use with specular lighting, and EXT_secondary_color came later to allow it to be used even if lighting was disabled. Unfortunately I can't see when the specular lighting calculation was actually fixed to be additive.
I suppose anything with proper additive specular behaviour is probably also going to have the secondary colour extension, making a specular hack slightly pointless.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Aramaz
Junior Devvie  
Java Games Rock!
|
 |
«
Reply #10 - Posted
2006-01-18 17:49:18 » |
|
I've not actually come across a machine without this extension yet. But the fallback is simply to use additive blending instead of alpha blending when rendering the sprite which makes it a lot brighter if there's any background image there already but otherwise has no effect on black backgrounds.
Sounds good that most cards have it... I think I'll just use the extension and don't worry about those without... they can live without the flash...  It's just to get a little more visual feedback when someone gets hit, so it's not crucial to the game itself. Thanx for all the suggestions.
|
|
|
|
DzzD
|
 |
«
Reply #11 - Posted
2006-01-18 18:09:09 » |
|
To better explain what I was meaning by using two texture have a look to the first demo there http://research.microsoft.com/~hoppe/ named "Continuous flash" download it and execute use the right scrollbar to determine luminosity. Bruno
|
|
|
|
Aramaz
Junior Devvie  
Java Games Rock!
|
 |
«
Reply #12 - Posted
2006-01-18 23:49:52 » |
|
Yes, I understood the 2 texture thing... but I don't want to keep 2 copies in memory...  Anyways, now I implemented the flash thing, works beautifully, thanx for the help.
|
|
|
|
princec
|
 |
«
Reply #13 - Posted
2006-01-19 11:04:11 » |
|
That flash code was developed for Alien Flux and I still use it in all my games to this day  Cas 
|
|
|
|
kappa
|
 |
«
Reply #14 - Posted
2006-01-19 11:21:19 » |
|
what i do is just use a brighten the texture in a paint program(like the gimp). so when i draw it i use something like glColor3f(0.5f, 0.5f, 0.5f); to draw it in its normal color.
When i need it to flash i just change the color to glColor3f(1.0f, 1.0f, 1.0f);.
|
|
|
|
oNyx
|
 |
«
Reply #15 - Posted
2006-01-19 15:36:25 » |
|
But then you lose half the range (contrast).
|
|
|
|
kappa
|
 |
«
Reply #16 - Posted
2006-01-19 16:41:09 » |
|
hmm, maybe so, but doesn't look to bad to my untrained eye. maybe increasing the contrast might help compensate for some of the loss?
|
|
|
|
Orangy Tang
|
 |
«
Reply #17 - Posted
2006-01-19 17:47:37 » |
|
Then you'd get banding (as you've reduced your effective colour range by half).
|
|
|
|
|