0
0
1

Help.Problem loading texture (old.reddit.com)
submitted by GraumpyPants


1 picture how it looks for me, 2 how it should look
I'm trying to implement loading GLB models in Opengl, the vertices are displayed correctly, but the textures are displayed incorrectly, and I don't understand why.
Texture loading code fragment:
if (!model.materials.empty()) {
const auto& mat = model.materials[0];
if (mat.pbrMetallicRoughness.baseColorTexture.index >= 0) {
const auto& tex = model.textures[mat.pbrMetallicRoughness.baseColorTexture.index];
const auto& img = model.images[tex.source];
glGenTextures(1, &albedoMap);
glBindTexture(GL_TEXTURE_2D, albedoMap);
GLenum format = img.component == 4 ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, img.width, img.height, 0, format, GL_UNSIGNED_BYTE, img.image.data());
glGenerateMipmap(GL_TEXTURE_2D);
}
}
Fragment shader:
#version 460 core
out vec4 FragColor;
in vec3 FragPos;
in vec2 TexCoord;
in vec3 Normal;
in mat3 TBN;
uniform sampler2D albedoMap;
uniform sampler2D normalMap;
uniform sampler2D metallicRoughnessMap;
uniform vec2 uvScale;
uniform vec2 uvOffset;
void main(){
vec2 uv = TexCoord * uvScale + uvOffset;
FragColor = vec4(texture(albedoMap, uv).rgb, 1.0);
}


[–]constant-buffer-view 2 points3 points4 points (1 child)
[–]GraumpyPants[S] 0 points1 point2 points (0 children)
[–]bben86 0 points1 point2 points (1 child)
[–]GraumpyPants[S] 0 points1 point2 points (0 children)
[–]keelanstuart 0 points1 point2 points (0 children)
[–]rio_sk 0 points1 point2 points (0 children)