Duplicating vertices via indices causes weirdness [SOLVED]

Started by
5 comments, last by HarriPellikka 11 years, 7 months ago
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]); // '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:
[attachment=10985:cube_prob_2.jpg]

... while this is how it SHOULD be:
[attachment=10986:cube_correct.jpg]

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?
Advertisement
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 | +---------------------------------------------------------------------+

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.

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 | +---------------------------------------------------------------------+

[quote name='Manabreak' timestamp='1346259201' post='4974486']
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.
[/quote]

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. :)

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. smile.png


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 | +---------------------------------------------------------------------+
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. smile.png 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 :D

This topic is closed to new replies.

Advertisement