I have some problems with texturing. Let me set up the scenario: I have a custom-written .FBX importer which reads vertices, indices and UV coordinates from a file. If I have a cube, it'll have 8 vertices, 36 indices and 36 UV coordinates, as each vertex is used for three faces.
Now, the geometry is represented nice and dandy, and if I trace the UV coordinates, they are supposed to be correct, but when I try to draw the cube with the texture, the texture is mapped in a nonsensical fashion. I cannot find the cause of this problem, and after a week of frustration, I decided to ask you guys.
I use a struct for the vertex data, which has three properties (position : float x 3, normal : float x 3, uv : float x 2). I end up having eight of these, which is correct. Then I have an integer list which keeps track of the indices, going like 0, 1, 2, 1, 2, 3 etc., you know the drill. Now, the hardest thing for me to understand is, how does OpenGL know which UV coordinate should be used, when there's only eight vertices but 36 uv coordinates? I have set up a VBO which points to all the vertex properties, and finally I draw the cube using a DrawElements call. I use a GLSL shader to texture the cube, and I pass the texture and the texture coordinates to the shader correctly (at least I assume so, because the texture shows up on the cube).
Where could the problem be? This is how it should look like:
... and this is what it actually looks like:
As you can see, some coordinates (the top) are correct, while the sides are somewhat "skewed". I have done no changes to my importer, and the coordinates worked just fine before I changed my rendering code to use shaders. The shader code is like this:
[source lang="plain"]VERTEX SHADER:#version 330uniform mat4 projection;uniform mat4 view;uniform mat4 world;layout(location = 0) in vec3 in_position;layout(location = 1) in vec3 in_normal;layout(location = 2) in vec2 in_texcoord;out vec4 worldpos;out vec3 normal;out vec2 texcoord;void main(void){ texcoord = in_texcoord; normal = in_normal; worldpos = projection * view * world * vec4(in_position, 1.0);}FRAGMENT SHADER:#version 330in vec4 worldpos;in vec3 normal;in vec2 texcoord;out vec3 out_diffuse;uniform sampler2D colorMap;void main(void){ out_diffuse = texture(colorMap, texcoord).xyz;}[/source]






