3
\$\begingroup\$

I'm a little confused with using indexed vbos in opengl. I understand that different each vertex can only have one uv. How would it be possible to map a texture onto a 3d object if you can't "unwrap" the object? Here's what I mean:

3D pyramid with 4 vertices, 4 uv coordinates

3D pyramid unwrapped, 3 shared vertices, 3 unshared vertices

It is impossible to map a texture to it without having more uv coordinates, right?

Is there a solution to this problem while still using indexed vbos? Can I make this work with only 4 vertices?

\$\endgroup\$
2
\$\begingroup\$

You can, however, not if you'r vertices use distinct UV's for each side.

Your example is, well, not the best. To use indexed VBOs, you need a few more vertices. For example, take a look at this Picture (found in google):

enter image description here

As you see on the right, a lot of faces share their vertices and each vertex uses the same UV. The more vertices your model has, the more vertices you can (probably) share, but, it will (almost) never work to have the exact same amount of shared vertex+UV pairs as you have unique vertices.

\$\endgroup\$
  • \$\begingroup\$ Ohh that makes a lot of sense. So when I load obj models into opengl, for every vertex that has multiple uv coordinates for the same vertex, I should just automatically create separate vertices instead, right? Also normals would probably have to be duplicated too. Thanks! \$\endgroup\$ – name Mar 10 '15 at 17:04
  • \$\begingroup\$ Yes, you have to do that since indexed rendering can't use different indices of different attributes, so if you use index 7 as first index, it will use the seventh vertex, the seventh UV and the seventh normal. This means, if you have one single vertex which can have two different UV's you have to add two "different" vertices where x,y,z are the same but u,v are different. \$\endgroup\$ – tkausl Mar 10 '15 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.