I am a noob in OpenGL ES 2.0 (for WebGL) and I'm trying to draw a simple model I've made with a 3D tool and exported to .fbx format. I've been able to draw some models that only have: A vertex buffer, a index buffer for the vertices, a normal buffer and a texture coordinate buffer, but this model now has a "UVIndex" and I'm not sure where am I supposed to put this UVIndex. My code looks like this:

GL.bindBuffer(GL.ARRAY_BUFFER, this.Model.House.VertexBuffer);
GL.vertexAttribPointer(this.Shader.TextureAndLighting.Attribute["vPosition"],3,GL.FLOAT, false, 0, 0);
GL.bindBuffer(GL.ARRAY_BUFFER, this.Model.House.NormalBuffer);
GL.vertexAttribPointer(this.Shader.TextureAndLighting.Attribute["vNormal"], 3, GL.FLOAT, false, 0, 0);
GL.bindBuffer(GL.ARRAY_BUFFER, this.Model.House.TexCoordBuffer);
GL.vertexAttribPointer(this.Shader.TextureAndLighting.Attribute["TexCoord"], 2, GL.FLOAT, false, 0, 0);

GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, this.Model.House.IndexBuffer);

GL.bindTexture(GL.TEXTURE_2D, this.Texture.HTex1);

GL.drawElements(GL.TRIANGLES, this.Model.House.IndexBuffer.Length, GL.UNSIGNED_SHORT, 0);

But my model renders totally incorrect and I think it has to do with the fact that I am ignoring this "UVIndex" in the .fbx file, since I've never drawn any model that uses this UVIndex I really have no clue on what to do with it.

This is the json file containing the model's data: http://pastebin.com/raw.php?i=G294TVmz


2 Answers 2


UVIndex represents a series of indices that index into the UV array.

However, OpenGL (and D3D) do not allow you to use multiple indices. Each attribute cannot have its own index; the index represents all attributes. Therefore, you need to massage your data a bit, so that everything comes from a single index list.

To put it another way, you cannot take an FBX file, turn it into JSON, load it, and expect OpenGL to render with it. You need to use a tool to regularize the vertex data.

  • \$\begingroup\$ Just for clarification, This means you have to use the UVIndex, to re order the UVvalues from the multiple secondary index so they correspond to the singular OpenGL 'elements' index? \$\endgroup\$
    – kevzettler
    Dec 12, 2021 at 22:32

The TexCoord array is just an array that stores all the possible values of your texture coordinates, so you can't directly access it. You have to index it via TexCoordIndices, much like Indices does it for the positions of the vertices.

And I would check for the negative values that you have in Indices, I'm pretty sure they represent backward-facing polygons and you have to reverse them manually (I doubt the GPU does this automatically).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .