@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(); }
@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 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(); }
private final void glVertex2f(final GL gl, final float x, final float y) { if(immModeSinkEnabled) { immModeSink.glVertex2f(x, y); } else { gl.getGL2().glVertex2f(x, y); } }
@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(); }
gl.glVertex2f(bx1, (float) (pos - margin)); gl.glVertex2f(bx1, (float) (pos + fontsize + margin)); gl.glVertex2f(bx2, (float) (pos + fontsize + margin)); gl.glVertex2f(bx2, (float) (pos - margin));
public void glutStrokeString(final int font, final String string) { final GL2 gl = GLUgl2.getCurrentGL2(); final StrokeFontRec fontinfo = getStrokeFont(font); final int len = string.length(); for (int pos = 0; pos < len; pos++) { final int c = string.charAt(pos) & 0xFFFF; if (c < 0 || c >= fontinfo.num_chars) continue; 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); } } }
/** * Main render method * * @param gl GL context */ public final void render(GL2 gl) { gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0, width, 0, height, -1, +1); gl.glColor4f(0f, 0f, 0f, .5f); // Fade background: gl.glBegin(GL2.GL_QUADS); gl.glVertex2f(0f, 0f); gl.glVertex2f(width, 0f); gl.glVertex2f(width, height); gl.glVertex2f(0f, height); gl.glEnd(); renderContents(gl); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPopMatrix(); }
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); } }
gl2.glBegin(gl2.GL_QUADS); gl2.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // red gl2.glVertex2f(-1.0f, -1.0f); gl2.glVertex2f(1.0f, -1.0f); gl2.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue gl2.glVertex2f(1.0f, 1.0f); gl2.glVertex2f(-1.0f, 1.0f); gl2.glEnd(); gl2.glPopAttrib();