• Create Account

## Duplicating vertices via indices causes weirdness [SOLVED]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1Manabreak  Members

141
Like
0Likes
Like

Posted 29 August 2012 - 09:19 AM

Okay, this is kind of a sequel to my last post: ( http://www.gamedev.n...-using-vboglsl/ )

Basically, I'm trying to create the needed vertices from a set of base vertices, indices and UV coordinates. I just can't get it right. Let's take a simple cube for an example: I have 8 base vertex coordinates (read from a FBX file), 36 indices for triangles and 36 UV coordinates, one for each index. Now, I need a new set of vertices with the UV coordinates mapped to them.

Let's assume I have vertex coordinates like this:
(1, 1, -1)
(1, -1, -1)
(-1, -1, -1)
(-1, 1, -1)
(1, 1, 1)
(1, -1, 1)
(-1, -1, 1)
(-1, 1, 1)


And indices list like this:
4,0,3
4,3,7
2,6,7
2,7,3
1,5,2
5,6,2
0,4,1
4,5,1
4,7,5
7,6,5
0,1,2
0,2,3


I tried a simple code like this:
List<Vertex> tempVerts = new List<Vertex>();
for(int i = 0; i < indices.Count; ++i)
{
tempVerts.Add(vertices[indices[i]]);  // 'vertices' is the list of the eight original vertices
}
vertices = tempVerts; // override the original list with the newly made one


.. but it cause a hell of a mess:

... while this is how it SHOULD be:

I'm losing my head here, because I KNOW it's a simple thing, yet I cannot get my mind around it. Please help me before I go bald from pulling my hair! Also, someone told me last time that there should be 24 unique vertices in the final version, but I get 36. Huh?

### #2Goran Milovanovic  Members

1104
Like
0Likes
Like

Posted 29 August 2012 - 10:45 AM

Why didn't you continue this discussion in that original thread ? .... It seems fairly relevant.

Anyway: The advice you were given, relating to 24 indices for 8 base vertices, assumes that you're drawing quads. So, for 8 vertices that specify the corners of some cube, you have a total of 6 faces, meaning that you need 24 indices to specify the 4 verts for each individual face (6 * 4 = 24).

+---------------------------------------------------------------------+

| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

### #3Manabreak  Members

141
Like
0Likes
Like

Posted 29 August 2012 - 10:53 AM

Why didn't you continue this discussion in that original thread ? .... It seems fairly relevant.

Anyway: The advice you were given, relating to 24 indices for 8 base vertices, assumes that you're drawing quads. So, for 8 vertices that specify the corners of some cube, you have a total of 6 faces, meaning that you need 24 indices to specify the 4 verts for each individual face (6 * 4 = 24).

This felt kind of a different problem, so I decided to pop up a new thread.

In fact, i'm using triangles as is the standard, quads are quite "dead" anyway.

### #4Goran Milovanovic  Members

1104
Like
0Likes
Like

Posted 29 August 2012 - 12:52 PM

In fact, i'm using triangles as is the standard, quads are quite "dead" anyway.

Where is this written? I don't think it's true.

In either case, if you're intent on using triangles, you have to make sure that your texture coordinate buffer stores the proper values for that geometry type.

+---------------------------------------------------------------------+

| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

### #5Manabreak  Members

141
Like
0Likes
Like

Posted 29 August 2012 - 01:12 PM

In fact, i'm using triangles as is the standard, quads are quite "dead" anyway.

Where is this written? I don't think it's true.

In either case, if you're intent on using triangles, you have to make sure that your texture coordinate buffer stores the proper values for that geometry type.

There's a lot of discussion about triangles over quads: hardware optimization towards triangles, triangles being quaranteed to be on a single plane etc.

Anyway, you're not really answering to the original question here. The problem here is not about texture coordinates, but the geometry, and not about using triangles or quads. Help is appreciated, if given.

### #6Goran Milovanovic  Members

1104
Like
0Likes
Like

Posted 29 August 2012 - 02:12 PM

There's a lot of discussion about triangles over quads: hardware optimization towards triangles, triangles being quaranteed to be on a single plane etc

Assuming that specifying your data in terms of triangles is more efficient then quads (and assuming that this efficiency gain is more than negligible): This doesn't make triangles "standard", and it certainly doesn't make quads "dead".

Did you try using quads? If not, you should, just to ensure that your general data pipeline is functioning properly.

Anyway, you're not really answering to the original question here.

The only question I noticed is "Huh?" - relating to your confusion about why people mentioned 24 indices. I think I explained that well enough, but if there's still something that you don't understand, feel free to ask additional questions.

The problem here is not about texture coordinates, but the geometry, and not about using triangles or quads.

... Ok. I mean, it's hard for me to be sure (or, as sure as you appear to be), because looking at your rendering, it seems like the texture coordinates are wrong; Almost like someone tried to use a texcoord buffer intended for quads to texture triangles.

It would probably help if you could post the code that actually populates the vbo - Maybe you're loosing your ordering when data is passed from your high-level container structures.

Sorry I couldn't be more helpful.

+---------------------------------------------------------------------+

| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

### #7Manabreak  Members

141
Like
0Likes
Like

Posted 29 August 2012 - 02:27 PM

Umm, the problem is quite clear when you look the images - the geometry is f'd up. It's the same object from the exact same perspective.

The order stays the same, I've checked it a million times. I've even tried disabling texturing and texture coordinates alltogether, it didn't help, so I really doubt it's the texture coordinates messing up the geometry.

EDIT:

Ugh, I finally solved it. I didn't notice that after I duplicated the vertices they were already in the correct order and I still used the old index array. Duh. Well, it works now

Edited by Manabreak, 30 August 2012 - 02:59 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.