Alpha channel

Hi there !

I’ am using FreeImage and to load GIFs. I use GIF_PLAYBACK to “generate” the picture for every frame. But now my question is, how can I make the picture transparent ? There should be an alpha channel, but that doesn’t work.

	
	GLuint*textures;
	
	FIMULTIBITMAP* gif=FreeImage_OpenMultiBitmap(FIF_GIF,"forgif.gif",false,true,true,GIF_PLAYBACK);

	const int pageCount=FreeImage_GetPageCount(gif);
	num=pageCount;

	textures=new GLuint[pageCount];

	glGenTextures(num, textures);

	int width;
	int height;

	int i;

	

	for (i=0;i<pageCount;i++)
	{
		FIBITMAP* page=FreeImage_LockPage(gif,i);
	  

		
		if(i==0)
		{
			width=FreeImage_GetWidth(page);
			height=FreeImage_GetHeight(page);
		}

		int w=FreeImage_GetWidth(page); // Local Width
		int h=FreeImage_GetHeight(page); // Local Height


		
	


	glBindTexture(GL_TEXTURE_2D, textures[i]);


	char* pixeles = (char*)FreeImage_GetBits(page);

	glTexImage2D(GL_TEXTURE_2D,0,4, width, height, 0, GL_BGRA,GL_UNSIGNED_BYTE,(GLvoid*)pixeles);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);


	GLenum Error = glGetError();

		

		

		FreeImage_UnlockPage(gif,page,false);
	}
	FreeImage_CloseMultiBitmap(gif,GIF_PLAYBACK);

What should I do to get transparency to work ?

Please help :sorrow:

Do you have blending turned on?

If you are sure how to use blending maybe the gifs tranparency is not recognized correctly:

From the FreeImage docs:

Transparency is supported individually for all pages, the first entirely transparent index in the
table is used, the rest of the table will be entirely opaque.

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

glBindTexture(GL_TEXTURE_2D,textures[ix]);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0,0,-30);
glBegin(GL_QUADS);

glColor3f(1,1,1);
//glColor3f(1,0,0);
glTexCoord2f(0,1);
glVertex3f(-10,10,0);

glTexCoord2f(1,1);
glVertex3f(10,10,0);

glTexCoord2f(1,0);
glVertex3f(10,-10,0);

glTexCoord2f(0,0);
glVertex3f(-10,-10,0);

glEnd();

        // TEST

//glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,0);
glBegin(GL_TRIANGLES);
glColor3f(1,0,1);
glVertex3f(-15,0,-1);
glVertex3f(15,15,0);
glVertex3f(15,-15,0);

  glEnd();

If I try differnt BlendFuncs, I get a black or white background on the textured quad…
What is wrong ?

EDIT:
Sorry for that, I solved it. :o
But why isn’t it possible to draw Objects BEHIND transparent objects ? :confused:

because of depth test.
so draw transparent objects last.

why isn’t it possible to draw Objects BEHIND transparent objects ?

Because objects don’t exist. There are only pixels.

The reason that opaque objects can be drawn “behind” other objects is because you are using the depth test to cull fragments that are behind pixels that were previously drawn.

When you’re doing transparency, you’re still just rendering to pixels, just like with opaque rendering. The difference is that you create a pixel color by combining the transparent object color with whatever the pixel is currently in the framebuffer. This is called “blending”. This creates a single framebuffer pixel color.

If you render something after doing this, it cannot magically know what the original color was, what the transparent color was, etc. It only knows what the color is currently in the framebuffer, and what the color is from the object being rendered. These are your only two inputs to the blending system.

So this also affects mirrors,glas and other translucent objects ?

So this also affects mirrors,glas and other translucent objects ?

Again, there is no such thing as “mirrors”, “glas” and so forth. There is only what is in the framebuffer, the current triangle you are rendering, and how to blend between the two. It is your job to use these tools to create something that looks like “mirrors” or “glas”.