@Override public void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color3f argColor) { Vec2 vec = getWorldToScreen(argPoint); GL2 gl = panel.getGL().getGL2(); gl.glPointSize(argRadiusOnScreen); gl.glBegin(GL2.GL_POINTS); gl.glVertex2f(vec.x, vec.y); gl.glEnd(); }
@Override public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); gl.glBegin(GL2.GL_TRIANGLE_FAN); gl.glColor4f(color.x, color.y, color.z, .4f); for (int i = 0; i < vertexCount; i++) { Vec2 v = vertices[i]; gl.glVertex2f(v.x, v.y); } gl.glEnd(); gl.glBegin(GL2.GL_LINE_LOOP); gl.glColor4f(color.x, color.y, color.z, 1f); for (int i = 0; i < vertexCount; i++) { Vec2 v = vertices[i]; gl.glVertex2f(v.x, v.y); } gl.glEnd(); gl.glPopMatrix(); }
@Override public void drawSegment(Vec2 p1, Vec2 p2, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); gl.glBegin(GL2.GL_LINES); gl.glColor3f(color.x, color.y, color.z); gl.glVertex3f(p1.x, p1.y, 0); gl.glVertex3f(p2.x, p2.y, 0); gl.glEnd(); gl.glPopMatrix(); }
@Override public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); gl.glBegin(GL2.GL_LINE_LOOP); gl.glColor4f(color.x, color.y, color.z, 1f); for (int i = 0; i < vertexCount; i++) { Vec2 v = vertices[i]; gl.glVertex2f(v.x, v.y); } gl.glEnd(); gl.glPopMatrix(); }
@Override public void drawCircle(Vec2 center, float radius, Vec2 axis, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS; float c = MathUtils.cos(theta); float s = MathUtils.sin(theta); float x = radius; float y = 0; float cx = center.x; float cy = center.y; gl.glBegin(GL2.GL_LINE_LOOP); gl.glColor4f(color.x, color.y, color.z, 1); for (int i = 0; i < NUM_CIRCLE_POINTS; i++) { gl.glVertex3f(x + cx, y + cy, 0); // apply the rotation matrix float temp = x; x = c * x - s * y; y = s * temp + c * y; } gl.glEnd(); gl.glBegin(GL2.GL_LINES); gl.glVertex3f(cx, cy, 0); gl.glVertex3f(cx + axis.x * radius, cy + axis.y * radius, 0); gl.glEnd(); gl.glPopMatrix(); }
@Override public void drawCircle(Vec2 center, float radius, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS; float c = MathUtils.cos(theta); float s = MathUtils.sin(theta); float x = radius; float y = 0; float cx = center.x; float cy = center.y; gl.glBegin(GL2.GL_LINE_LOOP); gl.glColor4f(color.x, color.y, color.z, 1); for (int i = 0; i < NUM_CIRCLE_POINTS; i++) { gl.glVertex3f(x + cx, y + cy, 0); // apply the rotation matrix float temp = x; x = c * x - s * y; y = s * temp + c * y; } gl.glEnd(); gl.glPopMatrix(); }
y = s * temp + c * y; gl.glEnd();
@Override public void drawTransform(Transform xf) { GL2 gl = panel.getGL().getGL2(); getWorldToScreenToOut(xf.p, temp); temp2.setZero(); float k_axisScale = 0.4f; gl.glBegin(GL2.GL_LINES); gl.glColor3f(1, 0, 0); temp2.x = xf.p.x + k_axisScale * xf.q.c; temp2.y = xf.p.y + k_axisScale * xf.q.s; getWorldToScreenToOut(temp2, temp2); gl.glVertex2f(temp.x, temp.y); gl.glVertex2f(temp2.x, temp2.y); gl.glColor3f(0, 1, 0); temp2.x = xf.p.x + -k_axisScale * xf.q.s; temp2.y = xf.p.y + k_axisScale * xf.q.c; getWorldToScreenToOut(temp2, temp2); gl.glVertex2f(temp.x, temp.y); gl.glVertex2f(temp2.x, temp2.y); gl.glEnd(); }
y = s * temp + c * y; gl.glEnd();
private final void glEnd(final GL gl) { if(immModeSinkEnabled) { immModeSink.glEnd(gl, immModeSinkImmediate); } else { gl.getGL2().glEnd(); } }
@Override void renderContents(GL2 gl) { // Get text bounds. Rectangle2D bounds = renderer.getBounds(getMessage()); // Render message background: final float bx1 = .45f * (float) (width - bounds.getWidth()); final float bx2 = .55f * (float) (width + bounds.getWidth()); final float by1 = .45f * (float) (height - bounds.getHeight()); final float by2 = .55f * (float) (height + bounds.getHeight()); gl.glBegin(GL2.GL_QUADS); gl.glColor4f(0f, 0f, 0f, .75f); gl.glVertex2f(bx1, by1); gl.glVertex2f(bx1, by2); gl.glVertex2f(bx2, by2); gl.glVertex2f(bx2, by1); gl.glEnd(); // Render message renderer.beginRendering(width, height); renderer.setColor(1f, 1f, 1f, 1f); renderer.setColor(1f, 1f, 1f, 1f); renderer.draw(getMessage(), (width - (int) bounds.getWidth()) >> 1, (height - (int) bounds.getHeight()) >> 1); renderer.endRendering(); }
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // clear // color // and depth // buffers gl.glLoadIdentity(); // reset the model-view matrix // ----- Your OpenGL rendering code here (Render a white triangle for // testing) ----- gl.glTranslatef(0.0f, 0.0f, -6.0f); // translate into the screen gl.glColor3f(r, g, b); gl.glBegin(GL.GL_TRIANGLES); // draw using triangles long delay = System.currentTimeMillis() - time; double angle = speed * delay * Math.PI / 2000; float c = (float) Math.cos(angle); float s = (float) Math.sin(angle); gl.glVertex3f(c, s, 0.0f); gl.glVertex3f(-s, c, 0.0f); gl.glVertex3f(-c, -s, 0.0f); gl.glEnd(); } @Override
public void glutStrokeCharacter(final int font, final char character) { final GL2 gl = GLUgl2.getCurrentGL2(); final StrokeFontRec fontinfo = getStrokeFont(font); final int c = character & 0xFFFF; if (c < 0 || c >= fontinfo.num_chars) return; final StrokeCharRec ch = fontinfo.ch[c]; if (ch != null) { for (int i = 0; i < ch.num_strokes; i++) { final StrokeRec stroke = ch.stroke[i]; gl.glBegin(GL.GL_LINE_STRIP); for (int j = 0; j < stroke.num_coords; j++) { final CoordRec coord = stroke.coord[j]; gl.glVertex2f(coord.x, coord.y); } gl.glEnd(); } gl.glTranslatef(ch.right, 0.0f, 0.0f); } }
protected void drawQuad(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d) { GL2 gl = dc.getGL().getGL2(); gl.glBegin(GL2.GL_QUADS); gl.glVertex3d(a.x, a.y, a.z); gl.glVertex3d(b.x, b.y, b.z); gl.glVertex3d(c.x, c.y, c.z); gl.glVertex3d(d.x, d.y, d.z); gl.glEnd(); }
/** This function draws a solid-shaded dodecahedron whose facets are rhombic and whose vertices are at unit radius. No facet lies normal to any coordinate axes. The polyhedron is centered at the origin. */ public void glutSolidRhombicDodecahedron() { final GL2 gl = GLUgl2.getCurrentGL2(); gl.glBegin( GL2GL3.GL_QUADS ); for( int i = 0; i < 12; i++ ) { gl.glNormal3dv( rdod_n[ i ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 0 ] ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 1 ] ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 2 ] ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 3 ] ],0 ); } gl.glEnd( ); }
/** This function draws a wireframe dodecahedron whose facets are rhombic and whose vertices are at unit radius. No facet lies normal to any coordinate axes. The polyhedron is centered at the origin. */ public void glutWireRhombicDodecahedron() { final GL2 gl = GLUgl2.getCurrentGL2(); for( int i = 0; i < 12; i++ ) { gl.glBegin( GL.GL_LINE_LOOP ); gl.glNormal3dv( rdod_n[ i ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 0 ] ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 1 ] ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 2 ] ],0 ); gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 3 ] ],0 ); gl.glEnd( ); } }
private static void recorditem(final GL2 gl, final float[] n1, final float[] n2, final float[] n3, final int shadeType) { final float[] q0 = new float[3]; final float[] q1 = new float[3]; diff3(n1, n2, q0); diff3(n2, n3, q1); crossprod(q0, q1, q1); normalize(q1); gl.glBegin(shadeType); gl.glNormal3fv(q1, 0); gl.glVertex3fv(n1, 0); gl.glVertex3fv(n2, 0); gl.glVertex3fv(n3, 0); gl.glEnd(); }
private void pentagon(final GL2 gl, final int a, final int b, final int c, final int d, final int e, final int shadeType) { final float[] n0 = new float[3]; final float[] d1 = new float[3]; final float[] d2 = new float[3]; diff3(dodec[a], dodec[b], d1); diff3(dodec[b], dodec[c], d2); crossprod(d1, d2, n0); normalize(n0); gl.glBegin(shadeType); gl.glNormal3fv(n0, 0); gl.glVertex3fv(dodec[a], 0); gl.glVertex3fv(dodec[b], 0); gl.glVertex3fv(dodec[c], 0); gl.glVertex3fv(dodec[d], 0); gl.glVertex3fv(dodec[e], 0); gl.glEnd(); }
@Override public void drawAxis( final AxisConfig<float[]> config ) { final GL2 gl = this.glad.getGL().getGL2(); gl.glPushMatrix(); this.orient( gl ); final float zero = 0.001f; gl.glBegin( GL.GL_LINE_STRIP ); { gl.glLineWidth( (float)config.getRenderingConfig().getThickness() ); gl.glColor3f( config.getRenderingConfig().getColour()[0], config.getRenderingConfig().getColour()[1], config.getRenderingConfig().getColour()[2] ); final float n1 = this.calculatePosition( config.getMinValue() ).floatValue(); final float n2 = this.calculatePosition( config.getMaxValue() ).floatValue(); // We draw in the x axis, so the orientation has to be set appropriately gl.glVertex3f( n1, zero, zero ); gl.glVertex3f( n2, zero, zero ); } gl.glEnd(); gl.glPopMatrix(); }