Author Topic: opengl blending  (Read 3122 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
opengl blending
« on: December 07, 2006 »
I'm trying to do something with blending but can't get it working. I'm wanting to take a texture and blend it with a colour from the pixel buffer :

texture_colour*dst_colour + dst_alpha*dst_colour

and have:

GlEnable(Gl_Blend)
glBlendFunc(GL_Dst_Color,GL_Dst_Alpha)

the 'texture_colour*dst_colour' works fine but the ' dst_alpha*dst_colour' part seems to add 'dst_alpha*white'

Anyone got any ideas what I'm doing wrong?
« Last Edit: December 07, 2006 by Stonemonkey »

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: opengl blending
« Reply #1 on: December 07, 2006 »
hmm im not really sure what you mean i usually do this for my blending.

glColor4f 1.0, 1.0, 1.0, 0.4
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA, GL_ONE
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: opengl blending
« Reply #2 on: December 07, 2006 »
ty ninogenio, it's for my lighting rather than alpha blending though and i've got it working now. Was something I was doing with multitexturing in an earlier stage.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: opengl blending
« Reply #3 on: December 07, 2006 »
Nino, you should probably use
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
otherwise you'll end up with a bit of a glow effect - or perhaps that's what you wanted in the first place?
ie. right now you have (0.4 in the alpha colour)
pixel = 0.4 * src + 1.0 * dst.
which is src and dst are both white would give you 1.4 * white (ie. overbright, so some colours near-white will end up white).
In the version I posted you have
pixel = 0.4 * src + (1.0-0.4) * dst.
which has a maximum of 1.0.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: opengl blending
« Reply #4 on: December 07, 2006 »
ahh right what am i thinking your right jim.

cheers for the pointer btw ;)
Challenge Trophies Won: