/** * Issue ogl commands needed for this renderable object. * * @param gl The gl context to draw with */ @Override public void render(GL2 gl) { // No coordinates, do nothing. if ((vertexFormat & COORDINATE_MASK) == 0) return; setVertexState(gl); if ((vertexFormat & EDGES) != 0) { gl.glEnableClientState(GL2.GL_EDGE_FLAG_ARRAY); gl.glEdgeFlagPointer(0, edgeBuffer); } gl.glDrawArrays(GL2.GL_QUADS, 0, numCoords); if ((vertexFormat & EDGES) != 0) { gl.glDisableClientState(GL2.GL_EDGE_FLAG_ARRAY); gl.glEdgeFlag(true); } clearVertexState(gl); }
/** * //! Draw an x-y-z frame. * * @param aAxisLengthScale * @param aAxisThicknessScale * @param aModifyMaterialState */ public static void jDrawFrame( final double aAxisLengthScale, final double aAxisThicknessScale, final boolean aModifyMaterialState) { // Triangle vertices: int nTriangles = 8; // Quad vertices: int nQuads = 16; GL2 gl = GLContext.getCurrent().getGL().getGL2(); // set material properties float[] fnull = {0, 0, 0, 0}; gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, fnull, 0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, fnull, 0); gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE); gl.glEnable(GL2.GL_COLOR_MATERIAL); gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); // enable vertex and normal arrays gl.glEnableClientState(GL2.GL_NORMAL_ARRAY); gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); if (aModifyMaterialState) { gl.glEnable(GL2.GL_COLOR_MATERIAL); gl.glColorMaterial(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE); gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL); } for (int k = 0; k < 3; k++) { gl.glPushMatrix(); // Rotate to the appropriate axis if (k == 0) { gl.glRotatef(-90.0f, 0, 1, 0); gl.glColor3f(1.0f, 0.0f, 0.0f); } else if (k == 1) { gl.glRotatef(90.0f, 1, 0, 0); gl.glColor3f(0.0f, 1.0f, 0.0f); } else { gl.glRotatef(180.0f, 1, 0, 0); gl.glColor3f(0.0f, 0.0f, 1.0f); } // scaling gl.glScaled(aAxisThicknessScale, aAxisThicknessScale, aAxisLengthScale); // render frame object gl.glVertexPointer(3, GL2.GL_FLOAT, 0, triVerticesBuffer); gl.glNormalPointer(GL2.GL_FLOAT, 0, triNormalsBuffer); gl.glDrawArrays(GL2.GL_TRIANGLES, 0, nTriangles * 3); gl.glVertexPointer(3, GL2.GL_FLOAT, 0, quadVerticesBuffer); gl.glNormalPointer(GL2.GL_FLOAT, 0, quadNormalsBuffer); gl.glDrawArrays(GL2.GL_QUADS, 0, nQuads * 4); gl.glPopMatrix(); } // disable vertex and normal arrays gl.glDisableClientState(GL2.GL_NORMAL_ARRAY); gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); }