2
\$\begingroup\$

I'm implementing a model class which loads OBJ and MTL files, and ran into an issue or question with face materials.

Consider the following example: It's a cube with 5 sides Gray and 1 side Green.

mtllib Materials.mtl

o Cube
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000

usemtl Green
f 7 8 4 3

usemtl Gray
f 5 8 2 1
f 6 7 3 2
f 8 5 1 4
f 1 2 3 4
f 8 7 6 5

The OBJ file obviously shares same vertices for adjacent faces even if the faces get different materials.

When drawing such a cube with OpenGL however, I would need to duplicate the vertices of the adjacent faces with different materials, since every vertex specifies the color it has - and I have two different colors for the same vertices here, depending on the face and the different material it has. If I wouldn't do that, the adjacent faces would smooth over to the different materials.

First: Did I get this correctly or am I missing an OpenGL "feature" here which lets me "specify" the color of a whole triangle / face rather than a single vertex?

Second: If not, is there an easier way to keep track of the faces materials and duplicating the adjacent vertices if they get different materials? What would be the easiest way to implement different materials on one object?

\$\endgroup\$
5
  • \$\begingroup\$ yes the only way is to duplicate your vertices or your indices \$\endgroup\$ Commented Feb 8, 2015 at 4:46
  • \$\begingroup\$ I see, without that, it probably wouldn't be challenging to load the OBJ files :D \$\endgroup\$
    – Ray
    Commented Feb 8, 2015 at 10:22
  • \$\begingroup\$ heres a good tutorial on obj parcing that might help. opengl-tutorial.org/beginners-tutorials/… \$\endgroup\$ Commented Feb 8, 2015 at 18:10
  • \$\begingroup\$ @AnthonyRaimondo thx very much, I was looking for a tut not as techy as the original spec \$\endgroup\$
    – Ray
    Commented Feb 8, 2015 at 21:33
  • \$\begingroup\$ @AnthonyRaimondo it doesn't go into detail about material vertex sharing though \$\endgroup\$
    – Ray
    Commented Feb 8, 2015 at 21:50

1 Answer 1

2
\$\begingroup\$

You need two vertexes in such this case. There is no way around it. If the faces have a different texture then you will need a different vertexes to define them. To simplify it you could try to save the mesh in such way - check whatever modelling program you use. Sometime it may be as simple as telling it not to weld vertexes together.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for clearing that up, I thought I was missing something. \$\endgroup\$
    – Ray
    Commented Feb 17, 2015 at 11:17

You must log in to answer this question.

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