DrawTriangle() bug?

edited June 2016 in raylib: shapes
The triangle is not rendered iff (far as I can tell) the y value of the second vector argument is less than or equal to the y value of the first vector argument. This does not affect DrawTriangleLines() (so it seems like it might be a kink with the RL_TRIANGLES mode of rlBegin)

So, for example,

DrawTriangleLines(
(Vector2){100,100},
(Vector2){125, 25},
(Vector2){150, 100},
BLACK
);

works fine, but

DrawTriangle(
(Vector2){100,100},
(Vector2){125, 25},
(Vector2){150, 100},
BLACK
);

does not render anything visible. But

DrawTriangle(
(Vector2){125,25},
(Vector2){100, 100},
(Vector2){150, 100},
BLACK
);

does work fine.

Comments

  • edited June 2016
    Hey! Good catch! :D Actually, that's the expected behaviour for a triangle...

    Internally raylib enables backface-culling, it means not drawing faces that are not oriented towards the camera. Face orientation depends on face normal vector and it depends on vertex definition order.

    When you define the vertices following a counter-clockwise order, the normal of the triangle points towards the ortographic 2D camera and the triangle is visible; when you define them in clockwise order, the triangle is only visible from the other side of the window. This convention could be changed but the one used is pretty standard.

    Here it is some more info: http://stackoverflow.com/questions/15041517/what-is-a-clockwise-face-in-opengl

    For other shapes drawing, I take care of vertex definition order internally but in the case of DrawTriangle(), vertex are just defined in the order they are passed to the function.

    DrawTriangleLines() just draws line by line and this convention does not apply.
  • Ah, I see! Thank you for explaining!
Sign In or Register to comment.