Archon 808
Archon 808

Reputation: 200

OpenGL : drawing line using degenerate triangle

In my engine, I want to avoid having line, and separate triangle types. I want to draw the lines using a triangle where 2 verts are identical. But in opengl, this triangle wont be displayed because it has zero area, and therefore can't cover a pixel.

Internally, at the driver level, an opengl line is drawn using a degenerate triangle, and a different rasterization rule is used where it draws at least one pixel per scanline.

D3d had some option where you could set the rasterization to always draw the first pixel per scan line--effectively accomplishing what I want in d3d.

But how can I do this with opengl? I don't see any command that would allow you to change the rasterization rules.

Upvotes: 3

Views: 1749

Answers (1)

Benjamin James Drury
Benjamin James Drury

Reputation: 2383

Well I did this exact thing by, of the three vertices necessary, using the first two as the start point of the line and then using glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) at the start of the line rendering object and glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) at the end.

Combine that with the appropriate enabling and disabling of face culling, and you've got yourself a perfectly good line renderer that still uses the triangle set up.

Upvotes: 3

Related Questions