OpenGL Line Width
You could try drawing a quad. Make it as wide as you want your line to be long, and tall as the line width you need, then rotate and position it where the line would go.
opengl glLineWidth() doesn't change size of lines
OpenGL implementations are not required to support rendering of wide lines.
You can query the range of supported line widths with:
GLfloat lineWidthRange[2] = {0.0f, 0.0f};
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange);
// Maximum supported line width is in lineWidthRange[1].
The required minimum for both limits is 1.0, meaning that support for line widths larger than 1.0 is not required. Also, drawing wide lines is a deprecated feature, and will not be supported anymore if you move to a newer (core profile) version of OpenGL.
An alternative to drawing wide lines is to render thin polygons instead.
OpenGL line thickness
glLineWidth()
is obviously easier if it meets your needs. There's one big caveat in ES 2.0, though: The maximum width supported by a specific device can be as low as 1.0. Which means that devices can be ES 2.0 compliant without supporting wide lines at all.
You can get the range of supported line widths with:
GLfloat lineWidthRange[2];
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange);
lineWidthRange[1]
will then be the maximum supported line width. Based on table 6.18 of the spec, the minimum allowed value for this limit is 1.
Based on this, drawing geometry (triangles) that give actual width to your lines is the only approach that is guaranteed to work across devices.
Set line width in OpenGL 3 / GLSL 130
Line width was never removed from OpenGL. It was deprecated, but in 3.1, when most of the deprecated features were removed, line width was not among them. So there's no reason you shouldn't be able to use it in OpenGL 3.1+ core profile.
Just don't create a "forward compatibility context", and you should be fine. Now yes, MacOS's OpenGL support doesn't let you create a 3.1+ context unless you declare it to be forward compatible. But MacOS deprecated OpenGL as a whole, so how long the API will be supported on that platform is unclear.
Opengl Es Line thickness
OpenGL draws lines at a fixed width measured in pixels, independent of the distance from the camera. If you need "lines" with a thickness that changes with the camera distance, you will have to draw them as polygons.
You can change the line width with glLineWidth()
, but it will still be a fixed width in pixels. Also, in OpenGL ES, implementations are only required to support line widths up to 1.0.
There are at least two main approaches to draw lines as polygons. One is that you draw a single quad for each line, and make sure that the quad is oriented towards the camera. The other approach is that you draw a "stick" (cylinder) consisting of multiple polygons. Depending on the precision you need, it might be enough to use as few as 4 polygons to approximate the cylinder, which basically makes it a long thin box.
Related Topics
Clarification Needed Regarding Getchar() and Newline
Std::Shared_Ptr Thread Safety Explained
C++ Equivalent to Java's Blockingqueue
How to Find the Size of an Int[]
A How to Create a Matrix in C++
How to Declare a Member Vector of the Same Class
C++ Exception:Throwing Std::String
Returning Large Objects in Functions
Check Variadic Templates Parameters for Uniqueness
This Regex Doesn't Work in C++
Convert Between String, U16String & U32String
How to Read File Content into Istringstream
Why/When Is _Declspec( Dllimport ) Not Needed
Taking the Address of a Temporary Object