Is there any easy way to load a TGA to a 2D quad?
The function I use now distort the TGA file and make the color
messed up.
GLuint loadTexture(const char * fname, int w, int h)
{
GLuint texture;
unsigned char * data;
FILE * file;
file = fopen(fname, "rb");
if(file == NULL) return 0;
data = (unsigned char *) malloc (w * h * 3);
fread(data, w * h * 3, 1, file);
fclose(file);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
free(data);
return texture;
}
I want to load a TGA and make it as easy as possible to make a
specific color on the texture transparent.
Anyone has any idea?