我在我的 iPhoneX 上使用 OpenGLES 绘制 ARFaceGeometry,我绘制了 GL_POINTS 和跟踪我脸部的点,但它似乎不是正确的结果,请任何人帮助我找出哪里出错了?
这是我的绘图代码:
ARFaceGeometry *faceGeometry = [[ARFaceGeometry alloc] initWithBlendShapes:self.faceAnchor.blendShapes];
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, faceGeometry.vertexCount*3*sizeof(GLfloat), faceGeometry.vertices, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GLuint textureCoordBuffer;
glGenBuffers(1, &textureCoordBuffer);
glBindBuffer(GL_ARRAY_BUFFER, textureCoordBuffer);
glBufferData(GL_ARRAY_BUFFER, faceGeometry.textureCoordinateCount*2*sizeof(GLfloat), faceGeometry.textureCoordinates, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GLuint indexBuffer;
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, faceGeometry.triangleCount*3*sizeof(unsigned short), faceGeometry.triangleIndices, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
[self.program setUniformMatrix4fv:@"u_pMatrix" value:self.projectionMatrix.m];
[self.program setUniformMatrix4fv:@"u_vMatrix" value:self.viewMatrix.m];
[self.program setUniformMatrix4fv:@"u_mMatrix" value:(GLfloat *)self.faceAnchor.transform.columns];
[self.program setUniform1i:@"maskTexture" value:[self.texture activeUnit:1]];
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
[self.program setAttribute:@"a_vertex" size:3 stride:3*sizeof(GLfloat) offset:0];
glBindBuffer(GL_ARRAY_BUFFER, textureCoordBuffer);
[self.program setAttribute:@"a_texture_coord" size:2 stride:2*sizeof(GLfloat) offset:0];
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glDrawElements(GL_POINTS, (int)faceGeometry.triangleCount*3, GL_UNSIGNED_SHORT, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);