Engineer
Engineer

Reputation: 8847

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) vs. glDraw*(GL_LINE_STRIP...)

I made an interesting, if confusing discovery today.

Thus far I've gotten by fine using glDraw*(GL_LINE_STRIP...) (or related GL_LINE* draw modes). Of course, this always requires some re-ordering of vertices in order to make the same vertex data work seamlessly between GL_TRIANGLES and GL_LINE_STRIP, but okay, all good there.

Then today I reintroduced some older code I had and found glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) among it. I looked it up and people were saying that while GL_BACK and GL_FRONT are deprecated in 3.3 core context, glPolygonMode is undeprecated, though supported only by GL_FRONT_AND_BACK as the first argument. So I tried it with GL_LINE as the second argument, along with glDraw*(GL_TRIANGLES...) and not only did it work perfectly, it also required none of the explicit re-ordering of vertices required to suit GL_LINE_STRIP. (I went back to an earlier configuration to test this).

Questions:

  1. What am I supposed to be using, in 3.3 core context? Is either method OK? The reason I ask is that I am wondering whether the line glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); is really even giving me a core profile, since it is after all only a hint to GLFW.

  2. Which approach is recommended? Are there performance impacts to the latter? It certainly seems a lot more convenient.

  3. Why even have glDraw*(GL_LINE*...) if this can be done via glPolygonMode?

Upvotes: 0

Views: 1575

Answers (1)

BDL
BDL

Reputation: 22167

Ad 1: Both methods are perfectly fine in OpenGL Core profile.

Ad 2: I'm not sure about this, but I guess that there will not be a huge performance difference.

Ad 3: This methods exist because one might also want to draw line objects that are not composed from triangles. Examples for this are circles or even straight lines.

Upvotes: 1

Related Questions