• Advertisement
Sign in to follow this  

Blending Meshes with DevIL

This topic is 2158 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 trying to blend a DevIL image on a 3d background using:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);

glEnable(GL_TEXTURE_2D);
glGenTextures(2, texName);

//3d texture
glBindTexture(GL_TEXTURE_2D, texName[0]);
. . .
glBindTexture(GL_TEXTURE_2D, texName[0]);
. . .
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_ALPHA, GL_FLOAT, texture);
glColor4f(1.0, 0.0, 0.0, 0.5); //fills rectangle with red around the image
glBegin(GL_QUADS);
. . .
glEnd();

//DevIL texture
glBindTexture(GL_TEXTURE_2D, texName[1]);
. . .
glBindTexture(GL_TEXTURE_2D, texName[1]);
. . .
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataTexture);
glBegin(GL_QUADS);
. . .
glEnd();

The most I can accomplish is to substitute the alpha channel around the image with a colour, in the case red, but what I want is to get rid of it. The glColor4f effect could also be achieved with glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, blendColor);
Any ideas? I can show more code of relevant parts.

Share this post


Link to post
Share on other sites
Advertisement
Can you post a fully 'render' function here, because it's not enough clear.

Share this post


Link to post
Share on other sites
The title should be "Blending Textures with DevIL"
Here you go:

void drawScene(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluPerspective(angle, aspect, 10.0f, 0.0f);
gluLookAt(eye_x, eye_y, eye_z, eye_x+center_x, 1.0f, eye_z+center_z, 0.0f, 1.0f, 0.0f);

dataTexture = ilGetData();
w = ilGetInteger(IL_IMAGE_WIDTH);
h = ilGetInteger(IL_IMAGE_HEIGHT);
f = ilGetInteger(IL_IMAGE_FORMAT);
bpp = ilGetInteger(IL_IMAGE_BPP);
printf("ilGetData = %p w=%d, h=%d bpp=%d \n", dataTexture, w, h, bpp);
initialTexture = malloc(w*h*bpp);
memcpy(initialTexture, dataTexture, w*h*bpp);
ilSetPixels(0, 0, 0, w, h, 1, f, IL_UNSIGNED_BYTE, initialTexture);
ilBindImage(ImgId);
glBindTexture(GL_TEXTURE_2D, texName[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataTexture);
//Draw image
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.13, 0.0, 9.8);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.13, 0.7, 9.8);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.12, 0.7, 9.8);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.12, 0.0, 9.8);
glEnd();

makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, texName[0]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_ALPHA, GL_FLOAT, texture);
glColor4f(1.0, 0.0, 0.0, 0.5); //fills rectangle with red around image
// Draw ground
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f, 0.0f, -10.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 10.0f, 0.0f, -10.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0f, 0.0f, 10.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-10.0f, 0.0f, 10.0f);
glEnd();

glutSwapBuffers();
}

I am using Glut with:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ALPHA);

The image is png, obviously. If I draw the ground before the image, the image won't appear. I tried using "glActiveTexture" but never managed to get the two textures to appear in one go.

Share this post


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

  • Advertisement