is it possible to draw a line with GLSL using GL_TRIANGLES?
The reason why i ask is i'm trying to draw a line with adobes molehill and it only draws triangle.
Cheers
is it possible to draw a line with GLSL using GL_TRIANGLES?
The reason why i ask is i'm trying to draw a line with adobes molehill and it only draws triangle.
Cheers
if you set edge rendering to be on, just draw a triangle with point 1 and 3 at the same position. It's not efficient, but it works.
If you can, use a geometry shader. Pass in two vertices and a line width, generate 4 points forming two triangles by shifting the vertices, render and be done... But drawing wide lines using triangles w/o a geometry shader can also be done in OpenGL ES 2.0 (no geometry shaders) and desktop OpenGL using only vertex shaders:
Generate your vertex data so that you duplicate the vertices for every line (4 vertices per line). For each vertex, pass two extra vec2/vec3 attributes for the vertices of the previous and the next line (for calculating correct line joins) OR simply pass the vec2/vec3 line direction. Also add a float vertex attribute that represents a "normal", a direction in which to shift each vertex. For one endpoint of a line (that now uses two vertices), set the "normal" to one direction and for the duplicate vertex to the opposite direction. Generate triangles of those vertices (via indexing or whatever) and render with GL_TRIANGLES.
In the vertex shader use the vertex and the previous or next vertex to calculate a line direction and (simple in the 2D case) generate a vector perpendicular to it. Multiply that by the "normal" you passed as a vertex attribute. This will shift your lines "to the sides" so that an actual triangle will be generated.
Generating lines that have a correct pixel size is simple in 2D (albeit with uniform scaling, but also possible with non uniform scaling) - use the scale factor from the model-view matrix (e.g. modelView[0][0]) and divide your line width by it in the vertex shader. In 3D, this is a bit more involved...
There is a good explanation of the technique here, animated examples here and source code here.