#### Archived

This topic is now archived and is closed to further replies.

# Why does this work

This topic is 5352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there, I'm playing around with triangle strips and I just can't figure out why this works:
struct CUSTOMVERTEX{
FLOAT x, y, z, rhw;
DWORD color;
};

CUSTOMVERTEX g_Vertices[] ={
{ 200.0f, 400.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255,255,000), },
{ 200.0f, 200.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255,000,000), },
{ 400.0f, 400.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255,000,000), },
{ 400.0f, 200.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255,000,000), },
};


As you can tell it draws a square, although I don't understand why since DirectX doesn't draw triangles that are drawn anticlockwise. The first three vertices are okay, but the last 3 are anticlockwise...so, why is that triangle drawn???? Thanks ATS [edited by - Atthestart on February 21, 2004 9:59:29 AM]

##### Share on other sites
I suppose you are rendering it as a triangle strip.
From the DirectX documentation:

D3DPT_TRIANGLESTRIP
Renders the vertices as a triangle strip. The backface-culling flag is automatically flipped on even-numbered triangles.

##### Share on other sites
So does that mean it draws EVERY triangle if there are an even number of them?

##### Share on other sites
No, it means that the "always clockwise" rule has exceptions when using triangle strips. Again, read the DX documentation where it's well explained.

Also, if you set you cull mode to D3DCULL_NONE, then every triangle will always render, whatever it's CW or CCW, don't know if you are doing that.

[edited by - Sante05 on February 21, 2004 10:08:42 AM]

##### Share on other sites
Could you just clarify how I specify the vertices...at the moment I'm guessing it is something like this:

1   2   3---------|   |   ||   |   |---------4   5   6

So if I specify:

1,2,4 (first triangle)
4,2,5 (second triangle)
5,2,3 (third triangle)
3,5,6 (third triangle)

Although, it says I shouldn't (advises) that no duplicate vertices are passed...how do I do something like this???

I'm very sorry for the questions which are probably very basic, although I'm struggling with it a tad...

Thank you

[edited by - Atthestart on February 21, 2004 10:18:59 AM]

##### Share on other sites
Well, in a triangle strip you specify the first triangle''s vertices, and then add one vertex for each triangle, so you should fill the buffer with the vertices in this order:

4-1-2-5-3-6

(4,1,2) is the first triangle
(1,2,5) the second
(2,5,3) the third

As you see, the drawing order keeps changing, if one triangle is CCW, the next one in CW, etc.

Thank you!

##### Share on other sites
quote:
Original post by Sante05
Well, in a triangle strip you specify the first triangle''s vertices, and then add one vertex for each triangle, so you should fill the buffer with the vertices in this order:

4-1-2-5-3-6

(4,1,2) is the first triangle
(1,2,5) the second
(2,5,3) the third

As you see, the drawing order keeps changing, if one triangle is CCW, the next one in CW, etc.

(from DX8.0 help file)

The system uses vertices v1, v2, and v3 to draw the first triangle, v2, v4, and v3 to draw the second triangle, v3, v4, and v5 to draw the third, v4, v6, and v5 to draw the fourth, and so on. Notice that the vertices of the second and fourth triangles are out of order; this is required to make sure that all the triangles are drawn in a clockwise orientation

##### Share on other sites
That''s funny, I thought the triangle strip was rendered with the following sequence, although I haven''t checked to see if it culls properly.

4,1,5,2,6,3 ??

That was the beauty of triangle strips - they saved memory and bandwidth. There is even apparently a "swap" instruction but I am not sure about it''s precise functionality

##### Share on other sites
quote:
Original post by Anonymous Poster
quote:
Original post by Sante05
Well, in a triangle strip you specify the first triangle''s vertices, and then add one vertex for each triangle, so you should fill the buffer with the vertices in this order:

4-1-2-5-3-6

(4,1,2) is the first triangle
(1,2,5) the second
(2,5,3) the third

As you see, the drawing order keeps changing, if one triangle is CCW, the next one in CW, etc.

(from DX8.0 help file)

The system uses vertices v1, v2, and v3 to draw the first triangle, v2, v4, and v3 to draw the second triangle, v3, v4, and v5 to draw the third, v4, v6, and v5 to draw the fourth, and so on. Notice that the vertices of the second and fourth triangles are out of order; this is required to make sure that all the triangles are drawn in a clockwise orientation

Yes, the DX documentation says that, but it refers to the following triangle strip:

2   4   6---------|   |   |---------1   3   5

In this case, as the documentation says, the sequence is 1-2-3-4-5-6

Atthestart, however, was using the following triangle strip (as you can see in its own post):

1   2   3---------|   |   |---------4   5   6

You can see he''s calling "4" to the vertex the documentation calls "1", he calls "1" to the vertex the documentation calls "2", etc. So, using the same sequence, it becomes 4-1-5-2-6-3

Yes, I confused the third and fourth vertices in my last post, which lead me to confuse the 2 last ones as well. The right sequence is the one the second AP said, sorry for that mistake.

To the first AP:

I won''t, however, consent you to say I''m "lying", while you just copypaste a piece of the documentation without even realizing if it''s useful for the guy who is asking.

That said, I hope this helped clarifying everything.

##### Share on other sites

This topic is 5352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632934
• Total Posts
3009302
• ### Who's Online (See full list)

There are no registered users currently online

×