LWJGL
May 21, 2012, 00:44:50 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Color overlay on Texture (sprite)  (Read 2090 times)
royger
Newbie
*
Posts: 8


WWW
« on: April 28, 2007, 13:59:05 »

Hello,

I'm trying to overlay a color over a sprite, so that the sprite turns red for a few seconds when hit, I add a sample as attachment.

I've loaded my texture with GL11.GL_TEXTURE_2D and GL11.GL_RGBA, any help would be apreciated.

Thanks and regards, Roger.
Logged
ndhb
Regular nerd
**
Posts: 70


« Reply #1 on: April 28, 2007, 15:26:42 »

Hi Roger.

One way of doing it is to change the blending function (glBlendFunc) when you character is hit (maybe you have a state that says he's been hit or damaged). Here's some pseudocode for blending red into what is drawn:

if (character.isDamaged()) {
  GL14.glBlendColor(0.8f, 0, 0, 0);
  GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_CONSTANT_COLOR);
  GL11.glEnable(GL11.GL_BLEND); // you might already have it enabled
  character.draw();
  GL11.glDisable(GL11.GL_BLEND); // you might want to leave it enabled - you might want to change your BlendFunc back or something third.
} else {
  character.draw();
}

(As usual, there's many ways to skin a cat.)

Regards
Nicolai de Haan Brøgger
Logged
royger
Newbie
*
Posts: 8


WWW
« Reply #2 on: May 08, 2007, 10:14:10 »

Hello,

Thanks for the reply, your code was really useful. I've had to change it a little, because I also use transparent sprites, so that's how it looks now:

GL14.glBlendColor(1f, 0, 0, 0);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_BLEND);

The problem is that it isn't really red, it looks like if the sprite has been dakened, but not red, there's a sample attached. Do you know a way to solve this? I've tryed changing the glBlendColor indexes, but with no luck so far.
Logged
Fool Running
Nerdus Imperius
*****
Posts: 647


« Reply #3 on: May 08, 2007, 11:36:35 »

you might need to enable texture modulation:
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
ndhb
Regular nerd
**
Posts: 70


« Reply #4 on: May 09, 2007, 13:43:34 »

The texture mode GL_REPLACE should be okay.

On my example the colours darken too when I use GL_ONE_MINUS_SRC_ALPHA but it turns red with GL_CONSTANT_COLOR

Have you tried playing around with other functions if GL_CONSTANT_COLOR doesn't work for you?

http://pyopengl.sourceforge.net/documentation/manual/glBlendFunc.3G.html

Also you can try paiting your quad in red and switch texturing mode from GL_REPLACE to GL_MODULATE or something...

- Nicolai de Haan Brøgger
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!