Hello Guest

glColor4f not setting alpha value

  • 4 Replies
  • 18192 Views
glColor4f not setting alpha value
« on: November 30, 2005, 22:20:03 »
I've got this in my code:

Code: [Select]


GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glRecti(100, 100, 200, 200);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
GL11.glRecti(150, 150, 250, 250);



So, we have a white rectangle with a semi transparent rectangle slightly overlapping in the top right corner.  However, the second rectangle is not semi transparent.  It seems to be ignoring the alpha value altogether.  Is there something that I failed to set up correctly?

*

Offline CaseyB

  • ***
  • 118
glColor4f not setting alpha value
« Reply #1 on: November 30, 2005, 23:31:22 »
Did you enable blending?

glColor4f not setting alpha value
« Reply #2 on: December 01, 2005, 16:00:48 »
Hmmm... I thought I read in another thread that blending didn't need to be enabled when using glColor4f.  I'll go ahead and try that and post my results.  Thanks, CaseyB.

glColor4f not setting alpha value
« Reply #3 on: December 01, 2005, 16:07:54 »
Consulting the Redbook, I found some blending code and added the following to my program

Code: [Select]


GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);



And it works perfectly!  Thanks again, CaseyB!!

*

Offline CaseyB

  • ***
  • 118
glColor4f not setting alpha value
« Reply #4 on: December 01, 2005, 16:13:13 »
Glad I could Help!!  :D