Texture Replication

Hi all,

I’m having a rather strange issue that I’m having a hard time tracking down. I have my program working such that I can load an image, bind it, and have it display correctly. My problem is, when I try and create two of my entities, it uses the last texture loaded on both of them. I’m using DevIL to load images for me (which appears to be working fine) and I’m getting my texture objects bound correctly (at least, it’s returning different names for each). Has anyone else had any other problems like this and might have a suggestion on where to look into? Thanks much!

Brian

DevIL will not manage multiple GL textures. ilBindImage does not switch GL to a different texture object.

You must create multiple texture objects and bind them before telling DevIL to hand the image data to GL.

If that did make sense or doesn’t work, post your texture setup code, please.

Hey,

Thanks for the quick response! Yes, your message makes sense and I’ll give it a try as soon as I get home from work Thanks!

Brian

Okay, I think I’m finally getting to the bottom of my issue here… it appears that ilGenImages is generating the same number multiple times? I’m not deleting any images in between my calls to ilGenImage or anything… am I wrong, or isn’t it supposed to automatically increment the image name (like opengl? which, btw, is incrementing like it’s supposed to

If you have any idea why this might be happening, I’d love to hear. Thanks!

Brian

Here’s my texturing code that goes along with my problem (obviously this isn’t 100% complete due to a lack of class definitions and such, but those should be pretty self-explanitory)

Image loading:
ilInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);

ilGenImages(1, &this->image_name);
ilBindImage(this->image_name);
ilLoadImage(filename);

ILuint Width = ilGetInteger(IL_IMAGE_WIDTH);
ILuint Height = ilGetInteger(IL_IMAGE_HEIGHT); 
ILubyte *Data = ilGetData();

glGenTextures(1, &this->texture);
glBindTexture(GL_TEXTURE_2D, this->texture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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, GL_RGB, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, Data);

ilDeleteImages(1, &image_name); 

Drawing:
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, this->texture);

glTexCoord2f(0.0, 0.0);
glVertex3d(this->verts[0].x, this->verts[0].y, this->verts[0].z);	// bottom left corner

glTexCoord2f(1.0, 0.0);
glVertex3d(this->verts[1].x, this->verts[1].y, this->verts[1].z);	// bottom right corner

glTexCoord2f(1.0, 1.0);
glVertex3d(this->verts[2].x, this->verts[2].y, this->verts[2].z);	// top right corner

glTexCoord2f(0.0, 1.0);
glVertex3d(this->verts[3].x, this->verts[3].y, this->verts[3].z);	// top left corner

I suggest you ask on the support forum for your image loading library. This appears to not be OpenGL related at all – and ceratainly not “advanced.”

I posted on the library forum as well. I posted here originally because I didn’t know if it was an issue with the library or opengl, and I posted back here in hopes of hearing from zeckensack again, as he has apparently used DevIL in the past. Thanks for being so helpful, though…

Yes, I’ve used DevIL, briefly. Your code appears to be correct. It’s expected that DevIL returns the same image name, because when you call ilGenImages the second time, you’ve already deleted the first DevIL-image. The name is free again, so it’s alright if DevIL reuses it.
(and besides, you’re reinitializing DevIL anyway)

The only thing I don’t really recognize is ilutRenderer(ILUT_OPENGL). If that turns on some automatic image forwarding to OpenGL, it may be the cause of your problems. Try removing that one line and see what happens.
(though IMO it shouldn’t do anything, as you don’t use any other ilut functions)

Anyway, the OpenGL related parts of the code are correct. I agree that this topic doesn’t exactly belong here. I now somewhat suspect that you simply pass the wrong filename to the function.