我想为该行着色,但没有在OpenGL es 2.0
中找到合适的APIglDrawArrays ( GL_LINES , 0, 2 );
glLineWidth( width_test );
使用上面的代码,我能够绘制一些宽度的线条。现在我想为同一条线上色。有人可以指导我使用API吗?
答案 0 :(得分:0)
您提供的信息很少,而您使用的是什么。解决方案的简短版本是将均匀添加到表示颜色的片段着色器中,然后在片段着色器中输出颜色。至少看到你的着色器可能会有所帮助。
所以要查看着色器颜色输出的位置:
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); // Will output white color (RGBA values)
要更改它可以修改的内容,您需要添加制服,以便您的着色器看起来像这样:
uniform lowp vec4 uniformColor;
void main() {
gl_FragColor = uniformColor;
}
现在这意味着您可以使用openGL API从CPU控制uniformColor
。您需要使用当前程序,找到统一位置并将要设置的值传递为颜色:
GLuint myShaderProgram; // Your program ID you got when creating the program.
GLfloat colorToSet[4] = {1.0f, .0f, .0f, 1.0f}; // Set whatever color, this should output red.
glUseProgram(myShaderProgram);
int uniformLocation = glGetUniformLocation(myShaderProgram, "uniformColor");
if(uniformLocation < 0) {
// Uniform locations must be 0 or greater, otherwise the uniform was not found in the shader or some other error occured
// TODO: handle exception
}
else {
glUniform4f(uniformLocation, colorToSet[0], colorToSet[1], colorToSet[2], colorToSet[3]);
}
... continue with drawing (glDrawArrays) ...