我正在使用教程中提供的以下顶点着色器:
"uniform mat4 matriceDessin;" +
"uniform mat4 matriceVueCamera;" +
"uniform vec3 positionLumiere;" +
"attribute vec4 positionsSommets;" +
"attribute vec3 vecteursNormaux;" +
"attribute vec4 couleursSommets;" +
"varying vec4 v_Color;" +
"void main() {" +
"vec3 sommet,vecteurNormal,directionLumiere;"+
"float distance,diffuse;" +
"sommet = vec3(matriceVueCamera * positionsSommets);" +
"vecteurNormal = vec3(matriceVueCamera * vec4(vecteursNormaux, 0.0));" +
"distance = length(positionLumiere - sommet);" +
"directionLumiere = normalize(positionLumiere - sommet);" +
"diffuse = max(dot(vecteurNormal, directionLumiere), 0.1);" +
"diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance)));" +
"v_Color = couleursSommets;" +
"gl_Position = matriceDessin * positionsSommets;" +
"}";
为了获取变量的位置,在成功创建并链接程序后,我使用:
GLES31.glUseProgram(programme);
pointeurSurPosition = GLES31.glGetAttribLocation(programme, "positionsSommets");
pointeurSurVecteurNormal = GLES31.glGetAttribLocation(programme, "vecteursNormaux");
pointeurSurPositionLumière = GLES31.glGetUniformLocation(programme, "positionLumiere");
pointeurSurMatriceDessin = GLES31.glGetUniformLocation(programme, "matriceDessin");
pointeurSurMatriceVueCaméra = GLES31.glGetUniformLocation(programme, "matriceVueCamera");
我面临的问题是,为检索
matriceVueCamera
,
positionLumiere
vecteursNormaux
始终返回-1(正确检索其他位置)。
根据文档,如果变量不是活动的,可能会发生这种情况,但是可以注意到它们在着色器中使用,因此它们应该被视为活动的,至少就我所理解的概念而言。
我试图用
glBindAttribLocation
在连接程序之前,但它没有帮助。
我使用OpenGL ES 3.1。