Jump to content
  • Advertisement
Sign in to follow this  

OpenGL DevIL Importing TGA with Alpha Channel Error

This topic is 2362 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
ilGenImages(1, &texid);
success = ilLoadImage(filename);
if (success)
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glGenTextures(1, &image);
glBindTexture(GL_TEXTURE_2D, image);
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;
Edited by iwoplaza

Share this post

Link to post
Share on other sites
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. Edited by szecs

Share this post

Link to post
Share on other sites
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){
glColor3f(r, g, b);
glBindTexture(GL_TEXTURE_2D, tex);
glTexCoord2f(0, 1);
glVertex3f(x, y,z);
glTexCoord2f(0, 0);
glTexCoord2f(1, 0);
glVertex3f(x+width, y+height,z);
glTexCoord2f(1, 1);
glVertex3f(x+width, y,z);

Share this post

Link to post
Share on other sites
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? Edited by szecs

Share this post

Link to post
Share on other sites

[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] Edited by iwoplaza

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!