My question is-> How do I make color 255,200 255 transparent in OpenGL? (transparent, I mean removing the color of pixels 255,225,255 or something works ...)
my texture loading functions from this tutorial -> http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=33
Note that I do not need to use Alpha Channels, I have a set of pre-made images with a custom color (255,225,255), which should be transparent / deleted pixels.
Some .tga download functions of my program:
Texture AllTextures[1000];
typedef struct
{
GLubyte * imageData;
GLuint bpp;
GLuint width;
GLuint height;
GLuint texID;
GLuint type;
} Texture;
bool LoadUncompressedTGA(Texture * texture, char * filename, FILE * fTGA)
{
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return false;
}
texture->width = tga.header[1] * 256 + tga.header[0];
texture->height = tga.header[3] * 256 + tga.header[2];
texture->bpp = tga.header[4];
tga.Width = texture->width;
tga.Height = texture->height;
tga.Bpp = texture->bpp;
if((texture->width <= 0) || (texture->height <= 0) || ((texture->bpp != 24) && (texture->bpp !=32)))
{
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return false;
}
if(texture->bpp == 24)
{
texture->type = GL_RGBA;
}
else
{
texture->type = GL_RGBA;
}
tga.bytesPerPixel = (tga.Bpp / 8);
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height);
texture->imageData = (GLubyte *)malloc(tga.imageSize);
if(texture->imageData == NULL)
{
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
fclose(fTGA);
return false;
}
if(fread(texture->imageData, 1, tga.imageSize, fTGA) != tga.imageSize)
{
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
if(texture->imageData != NULL)
{
free(texture->imageData);
}
fclose(fTGA);
return false;
}
for(GLuint cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel)
{
texture->imageData[cswap] ^= texture->imageData[cswap+2] ^=texture->imageData[cswap] ^= texture->imageData[cswap+2];
}
fclose(fTGA);
return true;
}
void LoadMyTextureTGA(int id,char* texturename)
{
if(LoadTGA(&AllTextures[id], texturename))
{
glGenTextures(1, &AllTextures[id].texID);
glBindTexture(GL_TEXTURE_2D, AllTextures[id].texID);
glTexImage2D(GL_TEXTURE_2D, 0, 3, AllTextures[id].width, AllTextures[id].height, 0, GL_RGB, GL_UNSIGNED_BYTE, AllTextures[id].imageData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
if (AllTextures[id].imageData)
{
free(AllTextures[id].imageData);
}
}
else
{
MessageBoxA(0,"Textures Loading Fail! Game will close now","Game Problem",0);
exit(1);
}
}