okay, something is very very wrong with the code i have written beyond the call to gluBind2DMipmaps().
this code will compile and execute:
for(int i = 0; i < testobj.nummaterials; i++)
{
if(testobj.materials[i].texture.filename.size() > 0)
{
cout << "Loading texture " << testobj.materials[i].texture.filename << endl;
ilGenImages(1, &ImageName);
ilBindImage(ImageName);
testobj.materials[i].texture.textureidnum = ilutGLBindTexImage();
// gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
// glTexImage2D(GL_TEXTURE_2D, 3, 3, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
ilDeleteImages(1, &ImageName);
}
cout << "testobj.nummaterials part 2: " << testobj.nummaterials << endl;
cout << "i part 2: " << i << endl;
}
so i added a check to make sure that the files were being opened correctly, and this code compiles and executes:
for(int i = 0; i < testobj.nummaterials; i++)
{
if(testobj.materials[i].texture.filename.size() > 0)
{
cout << "Loading texture " << testobj.materials[i].texture.filename << endl;
ilGenImages(1, &ImageName);
ilBindImage(ImageName);
if(ilLoadImage(const_cast<char*> (testobj.materials[i].texture.filename.c_str())) == IL_FALSE)
{
cout << "unable to open: " << testobj.materials[i].texture.filename << endl;
}
else
{
testobj.materials[i].texture.textureidnum = ilutGLBindTexImage();
// gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
// glTexImage2D(GL_TEXTURE_2D, 3, 3, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
ilDeleteImages(1, &ImageName);
}
}
cout << "testobj.nummaterials part 2: " << testobj.nummaterials << endl; // check to make sure that the nummaterials hasn't changed somehow
cout << "i part 2: " << i << endl; // same for the iterator
}
so i finally decide to uncomment the gluBuild2DMipmap(). it compiles however it then crashes on execution of this code:
for(int i = 0; i < testobj.nummaterials; i++)
{
if(testobj.materials[i].texture.filename.size() > 0)
{
cout << "Loading texture " << testobj.materials[i].texture.filename << endl;
ilGenImages(1, &ImageName);
ilBindImage(ImageName);
if(ilLoadImage(const_cast<char*> (testobj.materials[i].texture.filename.c_str())) == IL_FALSE)
{
cout << "unable to open: " << testobj.materials[i].texture.filename << endl;
}
else
{
testobj.materials[i].texture.textureidnum = ilutGLBindTexImage();
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
// glTexImage2D(GL_TEXTURE_2D, 3, 3, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
ilDeleteImages(1, &ImageName);
}
}
cout << "testobj.nummaterials part 2: " << testobj.nummaterials << endl;
cout << "i part 2: " << i << endl;
}
so i try commenting out gluBuild2DMipmap and uncommenting glTexImage2D and i get the same result as when i use gluBuild2DMipmap.
so i try uncommenting buildmipmap and recommenting teximage2d and commenting out:
cout << "testobj.nummaterials part 2: " << testobj.nummaterials << endl;
just to see what happens, and low-an-behold it all of a sudden compiles and executes! this is the code:
for(int i = 0; i < testobj.nummaterials; i++)
{
if(testobj.materials[i].texture.filename.size() > 0)
{
cout << "Loading texture " << testobj.materials[i].texture.filename << endl;
ilGenImages(1, &ImageName);
ilBindImage(ImageName);
if(ilLoadImage(const_cast<char*> (testobj.materials[i].texture.filename.c_str())) == IL_FALSE)
{
cout << "unable to open: " << testobj.materials[i].texture.filename << endl;
}
else
{
testobj.materials[i].texture.textureidnum = ilutGLBindTexImage();
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
// glTexImage2D(GL_TEXTURE_2D, 3, 3, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGB, GL_UNSIGNED_BYTE, ilGetData());
ilDeleteImages(1, &ImageName);
}
}
// cout << "testobj.nummaterials part 2: " << testobj.nummaterials << endl;
cout << "i part 2: " << i << endl;
}
the catch though is that after loading the first texture the value of i goes from the correct number of 1 (cause it is on loop #2 due to the first two materials not having a texture filename) to 28966984. how it does this is beyond me.
so i try uncommenting the “cout” statement and recompiling and executing and again it crashes. so i test taking out the
cout << "i part 2: " << i << endl;
statement and compiling and running the program. that runs fine too.
what does this mean? i have no clue other than something is royally effed up because no where should the value of i be changed except at the end of the for loop. and it should be noted that the value of nummaterial is not changing at any time. so i’m completely stuck. it makes no sense what is going on.
does anyone have any ideas?