0

That is what i got

I tried to import obects with image texture from blender to opengl (using Devil) but thats what i got. It seems like the images overlap all the screen covering all the objects in the scene. How can i solve this problem?

I think that the problem might be my blender model but i tried everything i could.

I am using this function for the texture

int LoadGLTextures(const aiScene* scene)
{
    ILboolean success;

    /* Before calling ilInit() version should be checked. */
    if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION)
    {
        ILint test = ilGetInteger(IL_VERSION_NUM);
        /// wrong DevIL version ///
        std::string err_msg = "Wrong DevIL version. Old devil.dll in system32/SysWow64?";
        char* cErr_msg = (char*)err_msg.c_str();

        return -1;
    }

    ilInit(); /* Initialization of DevIL */

    //if (scene->HasTextures()) abortGLInit("Support for meshes with embedded textures is not implemented");

    /* getTexture Filenames and Numb of Textures */
    for (unsigned int m = 0; m < scene->mNumMaterials; m++)
    {
        int texIndex = 0;
        aiReturn texFound = AI_SUCCESS;

        aiString path;  // filename

        while (texFound == AI_SUCCESS)
        {
            texFound = scene->mMaterials[m]->GetTexture(aiTextureType_DIFFUSE, texIndex, &path);
            textureIdMap[path.data] = NULL; //fill map with textures, pointers still NULL yet
            texIndex++;
        }
    }

    int numTextures = textureIdMap.size();

    /* array with DevIL image IDs */
    ILuint* imageIds = NULL;
    imageIds = new ILuint[numTextures];

    /* generate DevIL Image IDs */
    ilGenImages(numTextures, imageIds); /* Generation of numTextures image names */

    /* create and fill array with GL texture ids */
    textureIds = new GLuint[numTextures];
    glGenTextures(numTextures, textureIds); /* Texture name generation */

    /* define texture path */
    //std::string texturepath = "../../../test/models/Obj/";

    /* get iterator */
    std::map<std::string, GLuint*>::iterator itr = textureIdMap.begin();

    for (int i = 0; i < numTextures; i++)
    {

        //save IL image ID
        std::string filename = (*itr).first;  // get filename
        (*itr).second = &textureIds[i];   // save texture id for filename in map
        itr++;                                // next texture


        ilBindImage(imageIds[i]); /* Binding of DevIL image name */
        std::string fileloc = basepath + filename;  /* Loading of image */
        success = ilLoadImage((const wchar_t*)fileloc.c_str());

        fprintf(stdout, "Loading Image: %s\n", fileloc.data());

        if (success) /* If no error occured: */
        {
            success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); /* Convert every colour component into
            unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA */
            if (!success)
            {
                /* Error occured */
                fprintf(stderr, "Couldn't convert image");
                return -1;
            }
            //glGenTextures(numTextures, &textureIds[i]); /* Texture name generation */
            glBindTexture(GL_TEXTURE_2D, textureIds[i]); /* Binding of texture name */
            //redefine standard texture values
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* We will use linear
            interpolation for magnification filter */
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* We will use linear
            interpolation for minifying filter */
            glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
                ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
                ilGetData()); /* Texture specification */
        }
        else
        {
            /* Error occured */
            fprintf(stderr, "Couldn't load Image: %s\n", fileloc.data());
        }
    }
    ilDeleteImages(numTextures, imageIds); /* Because we have already copied image data into texture data
    we can release memory used by image. */

    //Cleanup
    delete[] imageIds;
    imageIds = NULL;

    //return success;
    return TRUE;
}
burnsi
  • 6,194
  • 13
  • 17
  • 27

0 Answers0