Stuck with DevIL texture problem (hours and hours)

Started by
6 comments, last by Bytez 17 years, 4 months ago
hi, if anyone can help it will be a major thing... ive been stuck most of the day on this problem, im using DevIL to load textures.

cTexture::cTexture(std::string nFilename, int nFlags)
{
	tBlend = 2;
	tScaleU = 1.0f; tScaleV = 1.0f;
	
	ilInit();
	iluInit();
	ilutRenderer(ILUT_OPENGL);
	ilutInit();
	
	tTextureHandle = ilutGLLoadImage((char*)nFilename.c_str());
}
i dont get any errors, but when i try and render my objects with texture, there is no texture at all. using gDebugger and forcing textures to 2x2 shows a black "mess" on the object that should be textured... im at a loss. any help would be amazing. im drawing with glDrawElements using vertex,normal,color and texture pointers, and my textures are setup

			glActiveTextureARB(GL_TEXTURE0 + nIndex);
			glClientActiveTextureARB(GL_TEXTURE0 + nIndex);
			
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, tBrush.GetTexture(nIndex));
			
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Advertisement
What is the size of the texture you are trying to load? In OpenGL you must use textures that have dimensions that are powers of two (eg. 2,4,8,...,64,128,256, etc.).
its exactly 256 x 256, just to note i see nothing wrong except no textures when i run the app normally, the black mess only happens if i force 2x2 in gDEBugger
Hi

It's difficult to know where to start. It's best to break things like this down into smaller problems. Firstly, are you sure your texcoords, normals and lighting are correct? Your post title makes it sound like you're pretty sure it's DevIL, but you mentioning DrawElements etc makes it sound like you think it could be something else.

When you say "there is no texture at all" what do you mean? And how is it different to the 'black mess'?

Texturing problems in OpenGL usually end up with gl using white instead of the texture colour. As you say there's a black mess, that black must be coming from somewhere - either your texture or lighting. Turn lighting off and see if the black is still there. If so, it's coming from the texture. Try different textures and try to relate them to what you're seeing.

FWIW, the code you posted looks fine.
[size="1"]
to check if texture loading and texture upload works properly you can try to read back the texture (glGetTexImage) and print out the buffer - if your texture is not to large you will be able to decide if the texturedata is ok.
when i mention no texture, basically there is color, the normals are correct (as lighting works) but nothing else, with lighting off i get the same problem, will try reading it back and outputting

with light disabled it looks like this (textured forced to 2x2) and with light enabled i also get the glitch.

EDIT: the glitch happens even if the texture dosent exist (as i removed checking to try this idea)

so it would seem, the texture isnt loaded? but... how.

This is how you are supposed to load a texture from DevIL:

    ILuint  imageID;    ILboolean success;    ilGenImages(1, &imageID);    ilBindImage(imageID);    success = ilLoadImage((char*)imageName.c_str());    if(!success)        //Error!    GLuint textureId = ilutGLBindTexImage(); //Use this in glBind calls in future


Also, you don't need to do ilInit() etc every time you create a texture. You do it just once.
ok, im a fool... it seems it was being initialized before gl was fully setup:) thanks all

This topic is closed to new replies.

Advertisement