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(); }
public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); glu = new GLU(); /* * jogl specific addition for tessellation */ tessellCallBack tessCallback = new tessellCallBack(gl, glu); // double rect[][] = new double[][] { // [4][3] in C; reverse here {50.0, 50.0, 0.0}, {200.0, 50.0, 0.0}, {200.0, 200.0, 0.0}, {50.0, 200.0, 0.0} }; double tri[][] = new double[][] { // [3][3] {75.0, 75.0, 0.0}, {125.0, 175.0, 0.0}, {175.0, 75.0, 0.0} }; double star[][] = new double[][] { // [5][6]; 6x5 in java {250.0, 50.0, 0.0, 1.0, 0.0, 1.0}, {325.0, 200.0, 0.0, 1.0, 1.0, 0.0}, {400.0, 50.0, 0.0, 0.0, 1.0, 1.0}, {250.0, 150.0, 0.0, 1.0, 0.0, 0.0}, {400.0, 150.0, 0.0, 0.0, 1.0, 0.0} }; gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); startList = gl.glGenLists(2); GLUtessellator tobj = glu.gluNewTess(); glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback); // glVertex3dv); glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback); // beginCallback); glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback); // endCallback); glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback); // errorCallback); /* rectangle with triangular hole inside */ gl.glNewList(startList, GL2.GL_COMPILE); gl.glShadeModel(GL2.GL_FLAT); glu.gluTessBeginPolygon(tobj, null); glu.gluTessBeginContour(tobj); glu.gluTessVertex(tobj, rect[0], 0, rect[0]); glu.gluTessVertex(tobj, rect[1], 0, rect[1]); glu.gluTessVertex(tobj, rect[2], 0, rect[2]); glu.gluTessVertex(tobj, rect[3], 0, rect[3]); glu.gluTessEndContour(tobj); glu.gluTessBeginContour(tobj); glu.gluTessVertex(tobj, tri[0], 0, tri[0]); glu.gluTessVertex(tobj, tri[1], 0, tri[1]); glu.gluTessVertex(tobj, tri[2], 0, tri[2]); glu.gluTessEndContour(tobj); glu.gluTessEndPolygon(tobj); gl.glEndList(); glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback); // vertexCallback); glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback); // beginCallback); glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback); // endCallback); glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback); // errorCallback); glu.gluTessCallback(tobj, GLU.GLU_TESS_COMBINE, tessCallback); // combineCallback); /* smooth shaded, self-intersecting star */ gl.glNewList(startList + 1, GL2.GL_COMPILE); gl.glShadeModel(GL2.GL_SMOOTH); glu.gluTessProperty( tobj, // GLU.GLU_TESS_WINDING_RULE, // GLU.GLU_TESS_WINDING_POSITIVE); glu.gluTessBeginPolygon(tobj, null); glu.gluTessBeginContour(tobj); glu.gluTessVertex(tobj, star[0], 0, star[0]); glu.gluTessVertex(tobj, star[1], 0, star[1]); glu.gluTessVertex(tobj, star[2], 0, star[2]); glu.gluTessVertex(tobj, star[3], 0, star[3]); glu.gluTessVertex(tobj, star[4], 0, star[4]); glu.gluTessEndContour(tobj); glu.gluTessEndPolygon(tobj); gl.glEndList(); glu.gluDeleteTess(tobj); }
@Override public void draw(final GL2 gl, final boolean picking) { JOGLRenderer renderer = drawer.getRenderer(); gl.glColor3d(1.0, 1.0, 1.0); if (picking) { if (renderer.colorPicking) { gl.glDisable(GL.GL_DITHER); gl.glDisable(GLLightingFunc.GL_LIGHTING); gl.glDisable(GL.GL_TEXTURE); int viewport[] = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); FloatBuffer pixels = FloatBuffer.allocate(4); gl.glReadPixels( renderer.camera.getLastMousePressedPosition().x, viewport[3] - renderer.camera.getLastMousePressedPosition().y, 1, 1, GL.GL_RGBA, GL.GL_FLOAT, pixels); gl.glEnable(GL.GL_DITHER); gl.glEnable(GLLightingFunc.GL_LIGHTING); gl.glEnable(GL.GL_TEXTURE); // Color index = new Color(pixels.get(0), pixels.get(1), pixels.get(2)); // System.out.println("color picked " + index.toString()); } else { gl.glPushMatrix(); gl.glInitNames(); gl.glPushName(0); double alpha = 0d; int size = objects.size(); double delta = size == 0 ? 0 : 1d / size; for (final List<T> list : objects) { alpha = alpha + delta; for (T object : list) { if (isFading) { double originalAlpha = object.getAlpha(); object.setAlpha(originalAlpha * alpha); object.draw(gl, drawer, picking); object.setAlpha(originalAlpha); } else { object.draw(gl, drawer, picking); } } } gl.glPopName(); gl.glPopMatrix(); } } else if (drawAsList) { Integer index = openGLListIndex; if (index == null) { index = gl.glGenLists(1); gl.glNewList(index, GL2.GL_COMPILE); double alpha = 0d; int size = objects.size(); double delta = size == 0 ? 0 : 1d / size; for (final List<T> list : objects) { alpha = alpha + delta; for (T object : list) { if (isFading) { double originalAlpha = object.getAlpha(); object.setAlpha(originalAlpha * alpha); object.draw(gl, drawer, picking); object.setAlpha(originalAlpha); } else { object.draw(gl, drawer, picking); } } } gl.glEndList(); } gl.glCallList(index); openGLListIndex = index; } else if (drawAsVBO) { if (vah == null) { GLU glu = renderer.getGlu(); vah = new VertexArrayHandler(gl, glu, renderer); vah.buildVertexArray(getObjects()); } else { // vah.loadCollada(null); } } else { for (final T object : getObjects()) { object.draw(gl, drawer, picking); } } }