How to make white transparent

Home / Uncategorized / How to make white transparent

I am playing with OGL’s blending. I have a white background. I draw quad on this background. The quad is binded with white and black texture. Colors array is filled with color and alpha values:
for (i = 0; i < IMAGE_WIDTH; i++) { for (j = 0; j < MAGE_HEIGHT; j++) { c = ((((i&0x8)==0)^((j&0x8))==0))*255; Image[i][j][0] = (GLubyte) c; Image[i][j][1] = (GLubyte) c; Image[i][j][2] = (GLubyte) c; Image[i][j][3] = (GLubyte) 255; }; Display textured quad:glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE); glDisable (GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texCheck); glLoadIdentity(); glTranslatef (0.0f, 0.0f, -9.0f); glBegin (GL_QUADS); glColor3f (1.0f, 1.0f, 1.0f); glTexCoord2f(0.0, 0.0); glVertex3f(-5.0f, -5.0f, 0.0f); glTexCoord2f(0.0, 1.0); glVertex3f( 5.0f, -5.0f, 0.0f); glTexCoord2f(1.0, 1.0); glVertex3f( 5.0f, 5.0f, 0.0f); glTexCoord2f(1.0, 0.0); glVertex3f(-5.0f, 5.0f, 0.0f); glEnd(); glDisable(GL_TEXTURE_2D); glEnable (GL_DEPTH_TEST); glDisable (GL_BLEND); Black color of the binded texture on the quad is invisible and works fine. What should I do to make white color of binded texture transparent and black color of binded texure not transparent. Thanks for the help:)

Your blend function should be

Supplying GL_ONE as second parameter means that destination color value is taken without taking source alpha value into account so no proper blending occurs.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *