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); } } }