我的代码是:
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
int bunnyDisplayList = glGenLists(1);
glNewList(bunnyDisplayList, GL_COMPILE);
List<Model> models = NPC.getModels();
glBegin(GL_TRIANGLES);
for (Model m : models) {
for (Model.Face face : m.getFaces()) {
Vector3f n1 = addVectors(m.getNormals().get(face.getNormalIndices()[0] - 1), m.getPosition());
glNormal3f(n1.x, n1.y, n1.z);
Vector3f v1 = addVectors(m.getVertices().get(face.getVertexIndices()[0] - 1), m.getPosition());
glVertex3f(v1.x, v1.y, v1.z);
Vector3f n2 = addVectors(m.getNormals().get(face.getNormalIndices()[1] - 1), m.getPosition());
glNormal3f(n2.x, n2.y, n2.z);
Vector3f v2 = addVectors(m.getVertices().get(face.getVertexIndices()[1] - 1), m.getPosition());
glVertex3f(v2.x, v2.y, v2.z);
Vector3f n3 = addVectors(m.getNormals().get(face.getNormalIndices()[2] - 1), m.getPosition());
glNormal3f(n3.x, n3.y, n3.z);
Vector3f v3 = addVectors(m.getVertices().get(face.getVertexIndices()[2] - 1), m.getPosition());
glVertex3f(v3.x, v3.y, v3.z);
}
}
glEnd();
glEndList();
模型被绘制(但是以透明的方式),但每次调用此函数时都会出现以下错误:
GL ERROR: 1282 - Invalid operation
答案 0 :(得分:0)
在调用glEnd之前,您有两次调用glBegin。从文档中,这将生成GL_INVALID_OPERATION(1282)。我猜你应该删除第一个,如果你打算在显示列表中绘制模型。
答案 1 :(得分:0)
您正在拨打glBegin(GL_TRIANGLES);
两次。删除第二个陈述。