Archived

This topic is now archived and is closed to further replies.

Basiror

i never had such a problem with alpha channels TGA

Recommended Posts

arg today i played around with some alpha channel textures and to my disappointment i realized that something is really screwed the blendfunction looks correct the problem is it doesn t draw blended TGAs with alpha channel although the loader loadsthem as 32 bit TGAs ->8bits per pixel 4 bytes RGBA any idea?
	glDepthMask(FALSE);
	

	glEnable(GL_BLEND)
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	


	glBindTexture(GL_TEXTURE_2D,bas.texID);
	glBegin(GL_QUADS);
	glTexCoord2f(0,0);glVertex3f(0,0,64);
	glTexCoord2f(0,1);glVertex3f(0,0,192);
	glTexCoord2f(1,1);glVertex3f(128,0,192);
	glTexCoord2f(1,0);glVertex3f(128,0,64);
	glEnd();
	glDisable(GL_BLEND);
	glDepthMask(TRUE);


thats my tga loading code, i have no idea whats wrong with it standard RGB tgas work fine but RGBAs simply stay invisible when i render them
[CODE]
BOOL CTGALoader::LoadTGA(char *filename,CTGA *pTGA)
{
	if(!filename)
		return FALSE;
	if(!pTGA)
		return FALSE;
	
	GLubyte		TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};			
	GLubyte		TGAcompare[12];							
	GLubyte		header[6];							
	GLuint		bytesPerPixel;							
	GLuint		imageSize;							
	GLuint		temp;								
	GLuint		type=GL_RGBA;							
	FILE *file = fopen(filename, "rb");						
	if(	file==NULL ||fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) ||	memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0||fread(header,1,sizeof(header),file)!=sizeof(header))			
	{
		if (file == NULL)							
			return FALSE;						
		else
		{
			fclose(file);							
			return FALSE;							
		}
	}

	pTGA->width  = header[1] * 256 + header[0];				
	pTGA->height = header[3] * 256 + header[2];				
    
 	if(	pTGA->width	<=0	||pTGA->height	<=0	||(header[4]!=24 && header[4]!=32))					
	{
		fclose(file);								
		return FALSE;								
	}
	pTGA->bpp	= header[4];	
	
	bytesPerPixel	= pTGA->bpp/8;	
	
	imageSize	= pTGA->width*pTGA->height*bytesPerPixel;
	
	pTGA->imageData=new BYTE[imageSize];//(GLubyte *)malloc(imageSize);	
	
	if(	pTGA->imageData==NULL ||fread(pTGA->imageData, 1, imageSize, file)!=imageSize)		
	{
		if(pTGA->imageData!=NULL)						
			free(pTGA->imageData);					

		fclose(file);								
		return FALSE;								
	} 


	for(GLuint i=0; iimageData;						
		pTGA->imageData[i] = pTGA->imageData[i + 2];			
		pTGA->imageData[i + 2] = temp;					
	}

	fclose (file);
	
	


	return TRUE;	
}

void CTGALoader::GenMapTexture(CTGA *pTGA)
{
	if(!pTGA)
		return;
	if(!pTGA->imageData)
		return;

	GLuint		type=GL_RGBA;
	glGenTextures(1, &pTGA->texID);					
	glBindTexture(GL_TEXTURE_2D, pTGA->texID);				
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	if (pTGA->bpp==24)								
	{
		type=GL_RGB;								
	}
	
	gluBuild2DMipmaps(GL_TEXTURE_2D,type,pTGA->width,pTGA->height,type,GL_UNSIGNED_BYTE,pTGA->imageData);

}

void CTGALoader::GenSkyTexture(CTGA *pTGA)
{
	if(!pTGA)
		return ;
	if(!pTGA->imageData)
		return ;

	GLuint		type=GL_RGBA;
	glGenTextures(1, &pTGA->texID);					
	glBindTexture(GL_TEXTURE_2D, pTGA->texID);				
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	if (pTGA->bpp==24)								
	{
		type=GL_RGB;								
	}
	
	gluBuild2DMipmaps(GL_TEXTURE_2D,type,pTGA->width,pTGA->height,type,GL_UNSIGNED_BYTE,pTGA->imageData);

}    

Share this post


Link to post
Share on other sites