Archived

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

Why does this work

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Guest 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.


read this and don''t lie:
(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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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.


read this and don''t lie:
(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 this post


Link to post
Share on other sites
Guest Anonymous Poster
(so called 1-st AP)

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

====================================================
SORRY, but ...

the correct sequence is 123 243 ...
but my point was that every second triangle is drawn in different direction, and no "culling flags".. but you can imagine it as the culling flag...



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

===
so, it''s 4-1-5 1-2-5


I agree that it''s very easy to confuse but my point was that every second triangle is drawn in swapped direction. And whoever said it" culling flags" - liar.
==

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.

==
OK you clarified it, but i can say that you are still lying ... AGAIN. So please dont lie.

But i can use another term if you dont like it. It''s not intended to sound too harsh, just a fact.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.