Results 1 to 3 of 3

Thread: transparent pixels

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    transparent pixels

    Hi,

    I have a program that has fire, but so far to show the fire correctly I must use

    glBlendFunc(GL_SRC_ALPHA,GL_ONE);

    This workes ok, but when it is very hard to see against a white background so I thought maybe it would be easier just to pick the pixels in the bmp file that I want to be transparent. Here is a thread that is on the topic http://www.opengl.org/discussion_boa...c;f=2;t=018804 , but I can't figure out how to convert the code they have into my bitmap loader below.

    Code :
    void text(UINT textureArray[], LPSTR strFileName, int ID)
    {
    	if(!strFileName)   return;
     
    	AUX_RGBImageRec *pBitMap = auxDIBImageLoad(strFileName);
     
    	if(pBitMap == NULL)	exit(0);
     
    	glGenTextures(1, &textureArray[ID]);
    	glBindTexture(GL_TEXTURE_2D, textureArray[ID]);
    	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitMap->sizeX, pBitMap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitMap->data);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	
     
    	if (pBitMap)										
    	{
    		if (pBitMap->data)								
    		{
    			free(pBitMap->data);						
    		}
    		free(pBitMap);									
    	}
    }
    all replies are greatly appreciated.

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: transparent pixels

    Code :
    for (x = 0; x < pBitMap->sizeX; x++)
    {
      for y = 0, y < pBitMap->sizeY; y++)
      {
        byte_ptr = pBitMap->data + x + y*pBitMap->sizeX;
        red = *byte_ptr;
        green = *(byte_ptr+1);
        blue = *(byte_ptr+2);
        alpha = *(byte_ptr+2);
     
        // premultiply rgb by alpha here and write back
        // remember these are unsigned chars so you need to convert 0-255 to 0.0-1.0 and back.
        // scale alpha down to modulate dst less with the new glBlendFunction
      }
    }
     
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    This is not as straightforward as you think, you need to change your blend equation to use source alpha for destination and premultiply the source rgb by alpha then replace alpha with a lower value. This will retain a partial glow and show you some color withot the dulling effects of a full src_a, 1-src_a blendfunc.

    So do this and change your blendfunc to glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) and you'll get decent results. The key is alpha used for destination modulation is less than the source alpha you premultiplied by.

    With some content it may already be premultiplied and you're doing a double modulate so bear this in mind before premultiplying.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Re: transparent pixels

    I'm sorry I must be dim witted or something I can't understand what you want me to do. I put that code into my program and set the variables, but I still can't get it to work.

Similar Threads

  1. Semi-transparent pixels on texture turning grey OpenGL-ES 2.0
    By Hank Finley in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-30-2013, 07:09 PM
  2. Depthmap: skip transparent pixels
    By MitchVL in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-04-2010, 06:57 AM
  3. Transparent pixels for billboards
    By Nrtesn Nyarlahotep in forum OpenGL: GLSL
    Replies: 5
    Last Post: 05-13-2008, 02:06 PM
  4. make some pixels transparent
    By blueepl in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-27-2006, 09:16 PM
  5. overlaying transparent and non transparent bitmaps
    By dodgyposse in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-13-2000, 01:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean