Depth, blending & cullingGL 1.0
glLineWidth
Sets the width in pixels of lines; in the core profile only 1.0 is guaranteed to work.
Signature
void glLineWidth(GLfloat width);
How it works
Applies to GL_LINES draws and to wireframe from glPolygonMode(GL_LINE). The catch: wide lines are deprecated in the core profile. A forward-compatible context (always the case on macOS) rejects any width above 1.0 with GL_INVALID_VALUE, and many drivers clamp it to 1 anyway.
For thick lines that work everywhere, draw each segment as a thin quad of two triangles, built on the CPU or in a geometry shader.
Parameters
widthGLfloat
Width in pixels, default 1.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_VALUE
- width ≤ 0, or > 1 in a forward-compatible core context.
Example
example.cpp
1glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
2glLineWidth(1.0f); // the only width every core context accepts