void setTextureToObject(char* textureFilename, int obj)
{
Mesh::Texture texture;
// this one works fine
Mesh::loadTexture(textureFilename, texture);
// glGenTextures returns the same IDs on different calls
glGenTextures(1, &(Objects[obj].gTextureAccessor));
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, Objects[obj].gTextureAccessor);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texture.width, texture.height, GL_RGB, GL_UNSIGNED_BYTE, texture.pTextureData);
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, texture.width, texture.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture.pTextureData);
Mesh::unloadTexture(texture);
}