Public Group

# Making Triangle Face the Right Way

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

## Recommended Posts

I need someone to explain this to me in a way that a COMPLETE IDIOT can understand. I'm using directX to make a square. Everything I've read says that if you draw the triangle in the clockwise direction, you can see it. So that's all well and good. But then I try to make a square. I draw the first triangle perfectly, and it works. But then I add the last vertex to make it a full square, and that triangle is BACKWARDS. Someone please explain for me.

##### Share on other sites
Are you sure you posted the examples correctly? You say the first is CW and the last is CCW, but they look like they have the same vertex values.

##### Share on other sites
No, sorry. I did have the comments wrong but I fixed it and the problem is still there.

##### Share on other sites
Quote:
 Original post by VegaObscuraNo, sorry. I did have the comments wrong but I fixed it and the problem is still there.
Could you post the revised code? It's hard to say what's wrong if we can't see what you're doing.

##### Share on other sites
Yes, sorry about that. I was not expecting a reply so quickly. Here is the attempted square, which shows only the first triangle properly.
        { 120.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, //top left        { 520.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), }, //bottom right        { 120.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), }, //bottom left        { 520.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 255, 0), }, //top right

##### Share on other sites
I still think a little more context would be helpful, but you might double check your vertices - to me that looks like a self-intersecting polygon (which you should not expect to be rendered correctly).

##### Share on other sites
A self intersecting polygon? How do you prevent that? Which vertices does DirectX use to create the next tri? The last 3 listed perhaps? I think that explains it. Thanks.

##### Share on other sites
Go here, and read - especially the bit titled "Winding Order of Vertices". That should help understand the winding order.

Look at what you posted above and, as jyk mentions, see how that ordering of vertices is neither clockwise nor counter-clockwise.

hth
F451

##### Share on other sites
I know sweet FA about DirectX, but I'd be trying:

{ 120.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, //top left
{ 520.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 255, 0), }, //top right
{ 520.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), }, //bottom right
{ 120.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), }, //bottom left

##### Share on other sites
Quote:
 Original post by VegaObscuraYes, sorry about that. I was not expecting a reply so quickly. Here is the attempted square, which shows only the first triangle properly. { 120.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, //top left { 520.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), }, //bottom right { 120.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), }, //bottom left { 520.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 255, 0), }, //top right

Draw a square on a piece of paper. With a different colourConnect the top-left to the bottom-right, then bottom-right to bottom-left, then bottom-left to top-right, (then top-right to top left). See the problem?

Now, starting at the top-left, draw another square, going clockwise. Make a note of which corner you draw first, second, third and fourth.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

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

• Total Topics
633324
• Total Posts
3011366
• ### Who's Online (See full list)

There are no registered users currently online

×