2

I need some C# OpenGL help. Im still kinda new to OpenGL and making a little render engine! The rendering works fine but today I added an OBJ File loader, which also worked fine but the UV is messed up. I used a File Parser made by chrisjansson on GitHub. (Link to the repo) The parser Works fine and returns the right values but Im not sure if Im using them correctly

Here's a screenshot of the Vertices and Normals working loaded from OBJ file (I disabled UVs in the shader for this)

Screenshot 1

But if I enable UVs this is what happenes:

Screenshot 2

Also yeah my texture is beautiful and right here if it helps

And here is my Code:

var objLoaderFactory = new ObjLoaderFactory();
var objLoader = objLoaderFactory.Create();
var fileStream = new FileStream(path, FileMode.Open);
var result = objLoader.Load(fileStream);

List<Vector3> verts = new List<Vector3>();
List<uint> elements = new List<uint>();
List<Vector3> normals = new List<Vector3>();
List<Vector2> uvs = new List<Vector2>();

foreach (Vertex v in result.Vertices)
{
    verts.Add(new Vector3(v.X,v.Y,v.Z));
}
foreach (Normal n in result.Normals)
{
    normals.Add(new Vector3(n.X,n.Y,n.Z));
}
foreach (Tex t in result.Textures)
{
    uvs.Add(new Vector2(t.X,t.Y));
}

foreach (Group g in result.Groups)
    foreach (Face f in g.Faces)
        foreach (FaceVertex i in f._vertices)
            elements.Add((uint)i.VertexIndex - 1);

I can also provide the obj file if needed!

Hope you people can help me! :P

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
RedCube
  • 25
  • 4
  • Does this answer your question? [How do I sort the texture positions based on the texture indices given in a Wavefront (.obj) file?](https://stackoverflow.com/questions/51708275/how-do-i-sort-the-texture-positions-based-on-the-texture-indices-given-in-a-wave) – Spektre Jun 11 '20 at 05:49
  • 1
    see the linked duplicate ... You have to duplicate&reindex vertexes that use more than one texture coordinate (and normals) those are usually on edges of shapes. Another option is to write shader that use 3 separate indices for: vertex , texture and normal ... – Spektre Jun 11 '20 at 05:50
  • 1
    @Spektre thanks for your answer but Ive found the problem and it was something else. well kinda you were right I needed to pass in the same vertices multiple times to get it to look right but my second problem is that I was stupid lol I passed in the Vertex Index instead of the texture index soo ofc that wouldnt work! But again Thanks ^^ – RedCube Jun 11 '20 at 07:20

0 Answers0