我只是在学习opengl 2.0。我想画许多不同长度、颜色和粗细的线。
与其逐个调用每条线的draw函数,我认为保留数组中所有线的属性并用单个draw函数绘制它们会更有效。我在着色器函数中为顶点坐标和颜色定义了两个属性。我用glVertexAttributePointer将我想要的功能分配给了顶点,但在设置线宽时遇到了问题。我将保存在数组中的厚度信息发送到着色器程序,但glLineWidth()函数在着色器程序中不起作用。除此之外,我还能做些什么?
线着色器
attribute vec3 aVertex;
attribute vec4 aColor;
attribute vec1 aThickness;
varying vec4 vertexColor;
void main()
{
vertexColor = aColor;
gl_Position = vec4(aVertex, 1.0);
glLineWidth(aThickness);
}
片段着色器
#version 100
precision mediump float;
varying vec4 vertex_color;
void main()
{
gl_FragColor = vertex_color;
}