Skip to content

Instantly share code, notes, and snippets.

View brokenprogrammer's full-sized avatar
🧠

Oskar Mendel brokenprogrammer

🧠
View GitHub Profile
@notnullnotvoid
notnullnotvoid / LineRenderer.cpp
Last active January 31, 2023 19:36
Line rendering code
/*
IMPORTANT INFO:
This code is made to be renderer-agnostic.
You would complete the implementation by implementing the triangle() function for your particular renderer.
The code is not written to make use of an index buffer, so it is not perfectly efficient in terms of memory usage.
You can replace the vector / matrix math with types from your own math library if you want, or leave it as-is.
This implementation assumes coordinates are in screen pixel space (circleDetail() relies on that fact).
If you want to draw partially transparent lines, you will need render all triangles of a line at the same depth
and use the less-than or greater-than or not-equal depth test (e.g. glDepthFunc(GL_LESS) or GL_GREATER or GL_NOTEQUAL)
because some triangles overlap.