Does anyone know why my texture mapping is failing? this is a very basic model loader of gltf files absolute basic

here is my code and if u like i can provide upload of the mode as well so u can run this from ur end

i dont know why my texture mapping is off? im not an advanced opengl coder but i have exhausted
all i know about how this works

so the model loads correctly butt he textures are off , in unity the model loads correctly and in my
app it doesnt , im using assimp for the loading of the model

Looks like your textures use a wrapping mode of CLAMP_TO_EDGE and the model expects something else, probably REPEAT.
In glTF the sampler fields wrapS, wrapT specify the wrapping mode, I don’t know what that maps to in assimp.

Probably what has said carsten_neumann. In addition, your should verify if you has set addressing mode for both U and V. But in that image it seems that part of the texturization is correct. Maybe some corruption occuried in the UV coordinates. Use RenderDoc to investigate it.

it was a tough egg to crack but found the bug hiding crashing the NVIDIA driver



> PS C:\gameProject\ver1.16-3D GAME ENGINE> gcc -g -O0 modelLoader3.c -o model_viewer3.exe -IC:/gameProject/include -LC:/gameProject/lib -lglew32 -lglfw3dll -lassimp -lopengl32 -lgdi32 -lm
> PS C:\gameProject\ver1.16-3D GAME ENGINE> ./model_viewer3.exe assets/after_the_rain/scene.gltf
> Model Viewer Starting...
> OpenGL Version: 3.3.0 NVIDIA 576.52
> GLSL Version: 3.30 NVIDIA via Cg compiler
> Creating shaders...
> Attempting to load model: assets/after_the_rain/scene.gltf
> Loading model: assets/after_the_rain/scene.gltf
> Model directory: assets/after_the_rain
> UV flipping disabled for glTF format
> Loading scene with Assimp...
> Scene loaded successfully:
>   Materials: 72
>   Meshes: 134
>   Textures: 0
> Processing scene nodes...
> Processing node: 'Sketchfab_model' (0 meshes, 1 children)
>   Processing child node 1/1
> Processing node: 'Root' (0 meshes, 122 children)
>   Processing child node 1/122
> Processing node: 'bat1-structure' (0 meshes, 1 children)
>   Processing child node 1/1
> Processing node: 'bat1-structure_0' (1 meshes, 0 children)
>   Processing mesh 'bat1-structure_0' with 1259 vertices
>     Vertices processed
>     Indices processed (3222 indices)
>     Processing material 0
>   Loading 1 texture_diffuse texture(s)...
>     Processing texture_diffuse texture: textures/bat1-structure_diffuse.png
>       Loading new texture...
>         Attempting to load: assets/after_the_rain/textures/bat1-structure_diffuse.png
>         stbi_load returned: success
>         Format: 6407, Components: 3, Size: 2048x2048
>         Bound texture
>         Uploaded texture data
>         Generated mipmaps
>         Set texture parameters
> Successfully loaded texture: assets/after_the_rain/textures/bat1-structure_diffuse.png (2048x2048)
>       Added to texture cache
>       Added to mesh texture list
>   Finished loading texture_diffuse textures
>   Loading 1 texture_specular texture(s)...
>     Processing texture_specular texture: textures/bat1-structure_specularGlossiness.png
>       Loading new texture...
>         Attempting to load: assets/after_the_rain/textures/bat1-structure_specularGlossiness.png
>         stbi_load returned: success
>         Format: 6407, Components: 2, Size: 2048x2048
>         Bound texture
> PS C:\gameProject\ver1.16-3D GAME ENGINE>
> 
> Edit
> Found it! The crash is happening on glTexImage2D when trying to upload a 2-component texture (Components: 2) but using RGB format (Format: 6407 = GL_RGB).
> 
> Fixed the format detection:
> Replaced this section 
> 
> 
> GLenum format = GL_RGB;
> if (nrComponents == 1)
>     format = GL_RED;
> else if (nrComponents == 3)
>     format = GL_RGB;
> else if (nrComponents == 4)
>     format = GL_RGBA;
> With:
> 
> 
> GLenum format = GL_RGB;
> if (nrComponents == 1)
>     format = GL_RED;
> else if (nrComponents == 2)
>     format = GL_RG;
> else if (nrComponents == 3)
>     format = GL_RGB;
> else if (nrComponents == 4)
>     format = GL_RGBA;
> else {
>     fprintf(stderr, "Unsupported texture format with %d components\n", nrComponents);
>     stbi_image_free(data);
>     glDeleteTextures(1, &textureID);
>     return 0;
> }
> The specular texture has 2 components (likely roughness + metallic) but the code was trying to upload it as RGB, which caused the OpenGL driver crash.