Sign in to follow this  

I cant load transparent bitmap

Recommended Posts

hi, I am having a problem in loading the transparent bitmap maybe my algo is wrong , hope you guys can figure and point me out that what parts are making problem thanks. Regards GLuint texture[1]; // Storage For One Texture ( NEW ) AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image { FILE *File=NULL; // File Handle if (!Filename) // Make Sure A Filename Was Given { return NULL; // If Not Return NULL } File=fopen(Filename,"r"); // Check To See If The File Exists if (File) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer } return NULL; // If Load Failed Return NULL } here i am setting the new texture with the transparent image which i just create by removing alpha channel's value and make it as 0. Texture::Texture(string filename,uint TexId,bool bIsTransparent,uchar r,uchar g,uchar b) { AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture unsigned char* PixelData; memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL if (TextureImage[0]=LoadBMP((char*)filename.c_str())) { //GLuint textures[1]; //glGenTextures(1, &texture[0]); // Create The Texture PixelData = TextureImage[0]->data ; if(bIsTransparent) { /*TextureImage[0]->data = SetTransparentColourofTexture(TextureImage[0]->data, TextureImage[0]->sizeX*TextureImage[0]->sizeY,r,g,b); SetTransparentColourofTexture(TextureImage[0]->data, TextureImage[0]->sizeX*TextureImage[0]->sizeY,r,g,b);*/ for (uint i = 0; i < TextureImage[0]->sizeX*TextureImage[0]->sizeY ; i += 4) { if (PixelData[i] == r && PixelData[i+1] == g && PixelData[i+2] == b) { // Make pixel transparent PixelData[i+3] = 0; } else { // Make pixel opaque //PixelData[i+3] = 255; } } } mTextureID = (UINT) TexId;//textures[0]; mImageWidth = TextureImage[0]->sizeX; mImageHeight = TextureImage[0]->sizeY; glBindTexture(GL_TEXTURE_2D, mTextureID); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, PixelData); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } }

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this