ILuint image = 0;
ilGenImages(1, &image);
ilBindImage(image);
ilLoadImage(path);
int w = ilGetInteger(IL_IMAGE_WIDTH);
int h = ilGetInteger(IL_IMAGE_HEIGHT);
BYTE *bits = new BYTE[w * h * 4];
ilCopyPixels(0, 0, 0, w, h, 1, IL_RGBA, IL_UNSIGNED_BYTE, bits);
GLuint textureID[1];
glGenTextures(1, &textureID[0]);//generate texture
glBindTexture(GL_TEXTURE_2D, textureID[0]);//work with this texture
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR );//set the min filter
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR );//set the mag filter
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND );
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)bits);
I use DeviL to load the image. The image in question is this:
Following an article I found on opengl's site
[spoiler]
15.080 How can I make part of my texture maps transparent or translucent? It depends on the effect you're trying to achieve.
If you want blending to occur after the texture has been applied, then use the OpenGL blending feature. Try this:
glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE);
You might want to use the alpha values that result from texture mapping in the blend function. If so, (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) is always a good function to start with.However, if you want blending to occur when the primitive is texture mapped (i.e., you want parts of the texture map to allow the underlying color of the primitive to show through), then don't use OpenGL blending. Instead, you'd use glTexEnv(), and set the texture environment mode to GL_BLEND. In this case, you'd want to leave the texture environment color to its default value of (0,0,0,0).
[/spoiler]
So thats what im doing.Blending is disabled (glDisable(GL_BLEND). I set up the texture environment like it says in the article.
int w, h;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, (int)textid);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
glBegin(GL_QUADS);
glTexCoord2i(0, 1);glVertex2f(x, y);
glTexCoord2i(0, 0);glVertex2f(x, y + h);
glTexCoord2i(1, 0);glVertex2f(x + w, y + h);
glTexCoord2i(1, 1);glVertex2f(x + w, y);
glEnd();
glDisable(GL_TEXTURE_2D);
This is the code I use to draw my plane. with that the result i get is :
[spoiler]
[/spoiler]
This is what I want to get:
[spoiler]
[/spoiler]
Can anyone help me? The block color is how it should be. And the alpha is being loaded correctly. Its values from 0 to 255.