DevIL Importing TGA with Alpha Channel Error

Started by
5 comments, last by iwoplaza 11 years, 10 months ago
I am working on a RPG game in C + + and OpenGL. I am Importing TGA images, using Devil library. I am trying to import an image with alpha channel, but in my game the image is displayed with a black background sad.png. Can you help me with this?

This is my code for importing alpha image:


GLuint loadAlphaTexture(const ILstring filename) {
ILuint texid;
ILboolean success;
GLuint image;
int finished;
ilInit();
ilGenImages(1, &texid);
ilBindImage(texid);
success = ilLoadImage(filename);
if (success)
{
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glGenTextures(1, &image);
glBindTexture(GL_TEXTURE_2D, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,ilGetData());
}
return image;
}
Advertisement
Are you sure it's not a fault in your rendering function?
Are you sure it's not a fault on the image editing/saving side? Photohsohop 7.0 can't even save TGA with alpha without a plugin.

Why do you need this line?

[font=courier new,courier,monospace]ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);[/font]

Your code looks okay anyway.
I'm saving images with GIMP. It's saving alpha channel.

My rendering func:

void DrawQuad(float x, float y,float z,float width,float height,float r,float g,float b,int tex){
glPushMatrix();
glLoadIdentity();
glColor3f(r, g, b);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex3f(x, y,z);
glTexCoord2f(0, 0);
glVertex3f(x,y+height,z);
glTexCoord2f(1, 0);
glVertex3f(x+width, y+height,z);
glTexCoord2f(1, 1);
glVertex3f(x+width, y,z);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}
Do you enable blending?
How you you set up your blending function?
[font=courier new,courier,monospace]glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)[/font] is the usual way to achieve what you want.
Also, do you set up a rendering environment explicitly (though it shouldn't be a problem, as it's [font=courier new,courier,monospace]GL_MODULATE[/font] by default, if I recall correctly)?
What does [font=courier new,courier,monospace]ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)[/font] do?

[color=#000000][font=verdana]llConvertImage converts the current bound image from its format/type to variables. You have full description here:[/font]http://www-f9.ijs.si...L/il/f00016.htm
[color=#000000][font=verdana]I don't use glBlendFunc.[/font]

If you don't use [font=courier new,courier,monospace]glBlendfunc[/font], then you probably don't enable blending either ([font=courier new,courier,monospace]glEnable(GL_BLEND);[/font])
Which means you won't have blending, which means the alpha channel of your image is ignored.
O.o Thanks. That works :).

This topic is closed to new replies.

Advertisement