• Advertisement
Sign in to follow this  

Making Triangle Face the Right Way

This topic is 3989 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

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


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


Link to post
Share on other sites
Quote:
Original post by VegaObscura
No, 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 this post


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


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


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


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


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


Link to post
Share on other sites
Quote:
Original post by VegaObscura
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


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement