[Plib-users] Texture with transparency
Brought to you by:
sjbaker
From: Michael W. <michael.wessels@z.zgs.de> - 2000-03-26 16:19:07
|
Hi all, I am using the following code to load a bmp-image with ssgTexture. --------------------------------------------------------------------------- // Load of a BMP-Image with the Library PLIB GLuint FDS_Load_Image_BMP(char *filename,GLuint tex_obj, bool transparent) { unsigned int i; int t_r,t_g,t_b,t_a; IMAGE_BMP bmp ; size_t npixels; GLuint tex_handle, map_level ; tex_list = new ssgTexture ( filename ) ; tex_handle = tex_list->getHandle(); if(transparent) { map_level = 7 ; glBindTexture(GL_TEXTURE_2D,tex_handle); glGetTexLevelParameteriv(GL_TEXTURE_2D,map_level,GL_TEXTURE_WIDTH,&bmp.width); glGetTexLevelParameteriv(GL_TEXTURE_2D,map_level,GL_TEXTURE_HEIGHT,&bmp.height); glGetTexLevelParameteriv(GL_TEXTURE_2D,map_level,GL_TEXTURE_COMPONENTS,&bmp.components); npixels = bmp.width * bmp.height ; bmp.raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32)); glGetTexImage(GL_TEXTURE_2D,map_level,GL_RGBA,GL_UNSIGNED_BYTE,&bmp.raster); for (i = 0; i < npixels; i++) { unsigned char *cp = (unsigned char *) &bmp.raster[i]; t_r = cp[0]; t_g = cp[1]; t_b = cp[2]; t_a = cp[3]; if((t_r==0)&&(t_g==0)&&(t_b==0)) { cp[3]=0; } else { cp[3]=255 ; } } glBindTexture(GL_TEXTURE_2D,tex_obj); glTexImage2D(GL_TEXTURE_2D,0,4,bmp.width,bmp.height, 0,GL_RGBA,GL_UNSIGNED_BYTE,bmp.raster); tex_handle = tex_obj ; } return tex_handle ; } ----------------------------------------------------------------------------------- The code works well, if a dont use transparent = false . I know that the images are put in SSG to a texture with using mipmaps. My understandig is, that I can get the image-raster using map_level = 0 glGetTexImage(GL_TEXTURE_2D,map_level,GL_RGB,GL_UNSIGNED_BYTE,&bmp.raster); . In this case the texture is completley transparent. The original bitmap has dimensions of 128*256. With map_level 6 I get a small stripe with two different colors in width direction. Has anybody an idea what I am making wrong ? With regards Michael |