How to draw surface/line/point at the same time?

Hi All,

Below is an example model which shows surfaces/lines/points in rendering view.
image

I would like to do the same thing but only thing I can do is something like

.
.
.
for (int i = 0; i < objects.size(); i++) {
    glDrawElements(GL_TRIANGLES, _ibo->getCount(), GL_UNSIGNED_INT, nullptr);
}
.
.
.

Above can only draw objects at once, with only surface.
But I would like to do draw surfaces/lines/points at the same time that I’ve tried

.
.
.
for (int i = 0; i < objects.size(); i++) {
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glDrawElements(GL_TRIANGLES, _ibo->getCount(), GL_UNSIGNED_INT, nullptr);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glDrawElements(GL_TRIANGLES, _ibo->getCount(), GL_UNSIGNED_INT, nullptr);

    glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
    glDrawElements(GL_TRIANGLES, _ibo->getCount(), GL_UNSIGNED_INT, nullptr);
}
.
.
.

Only thing I got is surfaces and even the rendering performance got slower and slower.
What is the way to achieve this with reasonable speed?

For a start, you need glDepthFunc(GL_LEQUAL). The initial value is GL_LESS, so drawing two fragments at the same depth will result in the second one being discarded. You might also need to use glPolygonOffset.

Also, the lines and points will probably want to use a shader which draws in a solid colour, without lighting. Otherwise the lines and points will be indistinguishable from the triangles.

Note that using glPolygonMode is less efficient than using separate index buffers, as every edge will be drawn twice and every point will be drawn once for each triangle using that vertex.

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.