-1

I write a Modelloader with Assimp in C++. The problem is that the Textures of the Model not show in the Programm. I am Positive that the Model has Textures. Here is the relevant Code:

Vertex Shader:

#version 330

in vec4 position;
uniform mat4 matrix;

layout(location = 1) in vec2 texCoords;

out vec2 TexCoord;
void main()
{

gl_Position=matrix*position;

TexCoord = vec2(texCoords);
}

Fragmet Shader:

 #version 330

 out vec2 TexCoord;
 out vec3 color;

 uniform sampler2D tex;

 void main(){
 color = texture(tex, TexCoord).rgb;
 };

Mesh Class:

    if(scene->HasMaterials()){
for(unsigned int i = 0; i < scene->mNumMaterials; i++){


    const aiMaterial* material = scene->mMaterials[i];
    int texIndex = 0;
    GLint texture;
    aiString path;

if(material->GetTexture(aiTextureType_DIFFUSE, texIndex, &path)==AI_SUCCESS){

        std::string textureDir = path.data;
        std::string fullPath = directory + '\\' + textureDir;

        std::cout << fullPath << std::endl; 

LoadTexture(fullPath,&t);

    }
}
}

And the LoadTexture method:

GLint Mesh::MeshEntry::LoadTexture(std::string path, struct TextureHandle *T){

        ilInit();
        ilEnable(IL_ORIGIN_SET);
        ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
        ILuint ImageNameID;
        ilGenImages(1,&ImageNameID);
        ilBindImage(ImageNameID);
        if(!ilLoadImage(path.c_str())){
            return 0;
        }
        ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
        T->id = ImageNameID;
        T->p = ilGetData();
        T->w = ilGetInteger(IL_IMAGE_WIDTH);
        T->h = ilGetInteger(IL_IMAGE_HEIGHT);
        T->DestFormat = ilGetInteger(IL_IMAGE_FORMAT);
        T->DestType = ilGetInteger(IL_IMAGE_TYPE);

        GLuint textureid;

        glGenTextures(1,&textureid);
        glBindTexture(GL_TEXTURE_2D,textureid);

        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_MIPMAP_LINEAR );
        glTexImage2D (GL_TEXTURE_2D, 0, t.DestFormat, t.w, t.h, 0, t.DestFormat, t.DestType, t.p);
        glGenerateMipmap(GL_TEXTURE_2D);


        GLint texloc = (glGetUniformLocation(ma.getProgrammID(),"tex"));

        glUniform1i(texloc,0); 
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D,textureid);
        return 1;

}

I know this code is not the best. So I need your help :).

1 Answers1

0

It works now. There wasnt a problem with the Loader. The path was wrong so IlLoadImage cant load the Files. My "fullPath" string was something like that: model\nano\nanosuit.obj\glass_dif.png

But it should be : "model\\nano\\arm_dif.png"

And there should be a "in" and not a "out" before TexCoord.

And btw. A very Big thank to your answers :)