androidopengl-eslinethickness

Opengl Es Line thickness


I am drawing a line on android in opengl es. The line draws fine. The only problem is that the line remains the same thickness no matter how close or far the camera is from it. Are there any solutions to this?


Solution

  • 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.