Exemple #1
0
  public void generateDisplaylist(GL2 gl) {
    displayList = gl.glGenLists(1);
    gl.glNewList(displayList, GL2.GL_COMPILE); // TODO Possible bug GL2? or
    // GL
    gl.glBegin(GL2.GL_TRIANGLES);

    for (int faceIndex = 0; faceIndex < triangulatedMesh.getNumberOfTriangles(); faceIndex++) {
      TriangleFacet f1 = triangulatedMesh.getFacet(faceIndex);
      Vector3 normalFace = f1.getNormal();
      Vector3 color = f1.getHalfEdge().getStartVertex().getColor();

      gl.glNormal3d(normalFace.get(0), normalFace.get(1), normalFace.get(2));
      gl.glColor3d(color.get(0), color.get(1), color.get(2));

      Vertex vx1 = f1.getHalfEdge().getStartVertex();
      Vector3 v1 = vx1.getPosition();

      Vertex vx2 = f1.getHalfEdge().getNextHalfEdge().getStartVertex();
      Vector3 v2 = vx2.getPosition();

      Vertex vx3 = f1.getHalfEdge().getNextHalfEdge().getNextHalfEdge().getStartVertex();
      Vector3 v3 = vx3.getPosition();

      gl.glNormal3d(vx1.getNormal().get(0), vx1.getNormal().get(1), vx1.getNormal().get(2));
      gl.glVertex3d(v1.get(0), v1.get(1), v1.get(2));

      gl.glNormal3d(vx2.getNormal().get(0), vx2.getNormal().get(1), vx2.getNormal().get(2));
      gl.glVertex3d(v2.get(0), v2.get(1), v2.get(2));

      gl.glNormal3d(vx3.getNormal().get(0), vx3.getNormal().get(1), vx3.getNormal().get(2));
      gl.glVertex3d(v3.get(0), v3.get(1), v3.get(2));
    }

    gl.glEnd();

    gl.glEndList();
  }