Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertices counter/clockwise

I am reading several books about OpenGL and in two of them they always define the vertices counter clockwise. From what I read this is very crucial because it determines where the front and back is.

But I am also reading the tutorial on http://www.arcsynthesis.org/gltut/ And he defines them clockwise.

const float vertexPositions[] = {
    0.75f, 0.75f, 0.0f, 1.0f,
    0.75f, -0.75f, 0.0f, 1.0f,
    -0.75f, -0.75f, 0.0f, 1.0f,
};

Shouldn't I always use the counter clockwise notation, because that is the default in opengl?

Also why is the type a float? Shouldn't it be a GLfloat?

like image 867
Maik Klein Avatar asked Dec 25 '12 16:12

Maik Klein


People also ask

How do you sort vertices of a polygon in counter-clockwise order?

By choosing an arbitrary (x, y) pair as your "center", you can compute the polar angle of each point relative to your center, and then sort them based on this angle. The end result sorts the polygon's point in clockwise/counterclockwise direction.

How do you tell if a curve is clockwise or counterclockwise?

If the determinant is negative, then the polygon is oriented clockwise. If the determinant is positive, the polygon is oriented counterclockwise.

How do you order vertices?

Order vertices of a convex polygon You can use the centroid as the origin and construct the vectors from the centroid to each vertex. For each vector, you can compute the angle made with the horizontal axis. You can then sort the angles, which provides a sequential ordering of the vertices of the convex polygon.


1 Answers

Shouldn't I always use the counter clockwise notation, because that is the default in opengl?

That is your choice. You can use CCW or CW notation. You can always override this behaviour with glFrontFace(). There is no difference for the hardware, which way to work, but, I guess, chosing CW might cause some unexpected troubles when trying to use third-party library which prefers CCW or something like that.

Also why is the type a float? Shouldn't it be a GLfloat?

It should be GLfloat. On the other hand, on most platforms float and GLfloat are exactly the same and one can't find any difference. Using GLfloat is better practice from portability point of view. Another consideration: it emphasizes that the variable is used for graphics rendering, so it's a good thing to do.

like image 142
Oleg Titov Avatar answered Sep 28 '22 06:09

Oleg Titov