/** paint the portal using gl. */ public void paint(GL gl, GLDrawable glc) { if (fill != null) { setColor(gl, fill); gl.glDisable(GL.GL_TEXTURE_2D); } gl.glLineWidth(lineWidth()); gl.glBegin(GL.GL_LINES); // draw each wall for (int i = 0; i < pts2d.size(); i++) { Point2D p = (Point2D) (pts2d.get(i)); gl.glVertex2d(p.x, p.y); } gl.glEnd(); if (pts2d.size() == 4) { /* Connect mid point of the two line segments with dotted line*/ gl.glLineStipple(1, (short) 0x0F0F); gl.glEnable(GL.GL_LINE_STIPPLE); gl.glLineWidth(1); gl.glBegin(GL.GL_LINES); Point2D mid = pts2d.get(0).interp(pts2d.get(1), 0.5); gl.glVertex2d(mid.x, mid.y); mid = pts2d.get(2).interp(pts2d.get(3), 0.5); gl.glVertex2d(mid.x, mid.y); gl.glEnd(); gl.glDisable(GL.GL_LINE_STIPPLE); } }
public void renderBox(GL gl) { gl.glDisable(GL_TEXTURE_2D); int c1 = Math.abs(this.hashCode()) % 256; int c2 = Math.abs(getImage().hashCode()) % 256; gl.glColor4f(c1 / 256f, c2 / 256f, ((c1 + c2) * 34) % 256 / 256f, 0.3f); gl.glPushMatrix(); gl.glTranslatef(bounds.getLeft(), bounds.getTop(), minHeight); gl.glScalef(bounds.getWidth(), bounds.getHeight(), maxHeight - minHeight); gl.glBegin(GL_QUADS); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 1, 0); gl.glVertex3f(1, 1, 0); gl.glVertex3f(1, 0, 0); gl.glVertex3f(0, 0, 1); gl.glVertex3f(0, 1, 1); gl.glVertex3f(1, 1, 1); gl.glVertex3f(1, 0, 1); gl.glEnd(); gl.glColor4f(1, 1, 0, 0.2f); gl.glBegin(GL_QUAD_STRIP); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 0, 1); gl.glVertex3f(0, 1, 0); gl.glVertex3f(0, 1, 1); gl.glVertex3f(1, 1, 0); gl.glVertex3f(1, 1, 1); gl.glVertex3f(1, 0, 0); gl.glVertex3f(1, 0, 1); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 0, 1); gl.glEnd(); gl.glPopMatrix(); }
// Draw scale graphic private void drawScale(DrawContext dc, double width, double height) { GL gl = dc.getGL(); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3d(0, height, 0); gl.glVertex3d(0, 0, 0); gl.glVertex3d(width, 0, 0); gl.glVertex3d(width, height, 0); gl.glEnd(); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3d(width / 2, 0, 0); gl.glVertex3d(width / 2, height / 2, 0); gl.glEnd(); }
private void drawLine(GL gl, float size, Node[] line) { gl.glLineWidth(size); gl.glPointSize(size); gl.glBegin(GL.GL_LINE_STRIP); for (Node pos : line) { drawVertex(gl, getLocalCoordinates(pos.getPos())); } gl.glEnd(); gl.glBegin(GL.GL_POINTS); for (Node pos : line) { drawVertex(gl, getLocalCoordinates(pos.getPos())); } gl.glEnd(); }
public void display(GL gl, float time, int screenWidth, int screenHeight) { // TODO: most of this only needs to be done once per frame, not per button. if (!visible) { return; } gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); if (flipx) { gl.glTranslatef(1.0f, 0.0f, 0.0f); gl.glScalef(-1.0f, 1.0f, 1.0f); } if (flipy) { gl.glTranslatef(0.0f, 1.0f, 0.0f); gl.glScalef(1.0f, -1.0f, 1.0f); } gl.glScalef(1.0f / screenWidth, 1.0f / screenHeight, 1.0f); if (isSelected() || (mDown && mOver)) { gl.glColor3f(0.6f, 0.6f, 0.8f); } else { gl.glColor3f(0.8f, 0.8f, 0.8f); } gl.glActiveTexture(GL.GL_TEXTURE0); marble.enable(); marble.bind(); gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glBegin(GL.GL_POLYGON); for (int n = 0; n < buttonShape.npoints; n++) { gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2); gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -0.5f); } gl.glEnd(); tex.enable(); tex.bind(); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glBegin(GL.GL_POLYGON); for (int n = 0; n < buttonShape.npoints; n++) { gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2); gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -1.0f); } gl.glEnd(); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); }
public void fire() throws IllegalActionException { if (_debugging) { _debug("Called fire()"); } ArrayToken lineStartToken = ((ArrayToken) lineStart.getToken()); ArrayToken lineEndToken = ((ArrayToken) lineEnd.getToken()); ArrayToken rgbColorValue = ((ArrayToken) rgbColor.getToken()); DoubleToken widthValue = (DoubleToken) width.getToken(); GL gl = ((GRODirector) getDirector()).getGL(); gl.glLineWidth((float) widthValue.doubleValue()); gl.glBegin(GL.GL_LINES); gl.glColor3d( ((DoubleToken) rgbColorValue.getElement(0)).doubleValue(), ((DoubleToken) rgbColorValue.getElement(1)).doubleValue(), ((DoubleToken) rgbColorValue.getElement(2)).doubleValue()); // origin of the line gl.glVertex3d( ((DoubleToken) lineStartToken.getElement(0)).doubleValue(), ((DoubleToken) lineStartToken.getElement(1)).doubleValue(), ((DoubleToken) lineStartToken.getElement(2)).doubleValue()); // ending point of the line gl.glVertex3d( ((DoubleToken) lineEndToken.getElement(0)).doubleValue(), ((DoubleToken) lineEndToken.getElement(1)).doubleValue(), ((DoubleToken) lineEndToken.getElement(2)).doubleValue()); gl.glEnd(); }
/** * Draw labels for picking. * * @param dc Current draw context. * @param pickSupport the PickSupport instance to be used. */ protected void doPick(DrawContext dc, PickSupport pickSupport) { GL gl = dc.getGL(); Angle heading = this.rotation; double headingDegrees; if (heading != null) headingDegrees = heading.degrees; else headingDegrees = 0; int x = this.screenPoint.x; int y = this.screenPoint.y; boolean matrixPushed = false; try { if (headingDegrees != 0) { gl.glPushMatrix(); matrixPushed = true; gl.glTranslated(x, y, 0); gl.glRotated(headingDegrees, 0, 0, 1); gl.glTranslated(-x, -y, 0); } for (int i = 0; i < this.lines.length; i++) { Rectangle2D bounds = this.lineBounds[i]; double width = bounds.getWidth(); double height = bounds.getHeight(); x = this.screenPoint.x; if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0); else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width; y -= this.lineHeight; Color color = dc.getUniquePickColor(); int colorCode = color.getRGB(); PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false); pickSupport.addPickableObject(po); // Draw line rectangle gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); try { gl.glBegin(GL.GL_POLYGON); gl.glVertex3d(x, y, 0); gl.glVertex3d(x + width - 1, y, 0); gl.glVertex3d(x + width - 1, y + height - 1, 0); gl.glVertex3d(x, y + height - 1, 0); gl.glVertex3d(x, y, 0); } finally { gl.glEnd(); } y -= this.lineSpacing; } } finally { if (matrixPushed) { gl.glPopMatrix(); } } }
public void paintTex(int glid, int target, int w, int h, int color) { float r, g, b, a; int ir, ig, ib, ia; ia = (color >> 24) & 0xff; ir = (color >> 16) & 0xff; ig = (color >> 8) & 0xff; ib = color & 0xff; a = ia / 255.0f; r = ir / 255.0f; g = ig / 255.0f; b = ib / 255.0f; pushFramebuffer(); setFramebuffer(FBO); FBO.setDrawBuffer(target, glid); saveView(); setOrthographicView(w, h); gl.glColor4f(r, g, b, a); gl.glBegin(GL.GL_QUADS); gl.glVertex2f(0.0f, 0.0f); gl.glVertex2f(w, 0.0f); gl.glVertex2f(w, h); gl.glVertex2f(0.0f, h); gl.glEnd(); restoreView(); popFramebuffer(); }
public void drawRectangle(GL gl) { gl.glBegin(GL.GL_LINE_LOOP); for (int i = 0; i < p.length; i++) { gl.glVertex2d(p[i][0], p[i][1]); } gl.glEnd(); }
private static final void renderReference( final GL gl, final float[] origin, final float[] xAxis, final float[] yAxis, final float[] zAxis) { for (int i = X; i <= Z; ++i) { xAxis[i] = origin[i] + xAxis[i] * AXIS_SCALE; yAxis[i] = origin[i] + yAxis[i] * AXIS_SCALE; zAxis[i] = origin[i] + zAxis[i] * AXIS_SCALE; } gl.glBegin(GL.GL_LINES); { // X axis (red) gl.glColor3f(1, 0, 0); gl.glVertex3fv(origin, 0); gl.glVertex3fv(xAxis, 0); // Y axis (green) gl.glColor3f(0, 1, 0); gl.glVertex3fv(origin, 0); gl.glVertex3fv(yAxis, 0); // Z axis (blue) gl.glColor3f(0, 0, 1); gl.glVertex3fv(origin, 0); gl.glVertex3fv(zAxis, 0); } gl.glEnd(); }
@Override public void render(GLCanvas canvas) { gui.getGL().glColor4f(bg_col.getR(), bg_col.getG(), bg_col.getB(), bg_col.getA()); renderQuad(pos.x, pos.y, width, height); GL gl = canvas.getGL(); if (texture != null) { texture.bind(0); gl.glColor4f(fg_col.getR(), fg_col.getG(), fg_col.getB(), fg_col.getA()); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(0, 0); gl.glVertex2f(pos.x, pos.y); gl.glTexCoord2f(texture.getImageWidth() / texture.getWidth(), 0); gl.glVertex2f(pos.x + width, pos.y); gl.glTexCoord2f( texture.getImageWidth() / texture.getWidth(), texture.getImageHeight() / texture.getHeight()); gl.glVertex2f(pos.x + width, pos.y - height); gl.glTexCoord2f(0, texture.getImageHeight() / texture.getHeight()); gl.glVertex2f(pos.x, pos.y - height); gl.glEnd(); texture.unbind(); } gui.getGL() .glColor4f(border_col.getR(), border_col.getG(), border_col.getB(), border_col.getA()); renderOutlinedQuad(pos.x, pos.y, width, height); }
public void draw_fordisplaylist(GL gl) { // for gl createLists gl.glBegin(gl.GL_LINES); if (gl != null) { for (Line l : lines) { l.draw_forLists(gl); } } gl.glEnd(); }
public void line(Coord c1, Coord c2, double w) { texsel(-1); gl.glLineWidth((float) w); gl.glBegin(GL.GL_LINES); glcolor(); vertex(c1); vertex(c2); gl.glEnd(); checkerr(); }
// Draw scale rectangle private void drawRectangle(DrawContext dc, double width, double height) { GL gl = dc.getGL(); gl.glBegin(GL.GL_POLYGON); gl.glVertex3d(0, height, 0); gl.glVertex3d(0, 0, 0); gl.glVertex3d(width, 0, 0); gl.glVertex3d(width, height, 0); gl.glVertex3d(0, height, 0); gl.glEnd(); }
/** * Renders the tile to the given context, in the process building all needed resources. * * @param gl */ public void render(GL gl) { projection = ProjectionFactory.getCurrentProjection(); heightmap = State.getInstance().getLoadedHeightmap(); // BUILD TEXTURES IF NECESSARY if (!gl.glIsTexture(textureID)) { textureID = createTexture(gl, getImage(), false); // prerenderToTexture(gl); } if (!gl.glIsTexture(grainTextureID)) { createGrainTexture(gl); } // RENDER TILE FROM DISPLAY LIST, OR ELSE BUILD DISPLAY LIST if (gl.glIsList(displaylistID)) { gl.glCallList(displaylistID); } else { displaylistID = gl.glGenLists(1); gl.glNewList(displaylistID, GL_COMPILE_AND_EXECUTE); gl.glActiveTexture(GL_TEXTURE0); gl.glEnable(GL_TEXTURE_2D); gl.glBindTexture(GL_TEXTURE_2D, grainTextureID); gl.glActiveTexture(GL_TEXTURE1); gl.glEnable(GL_TEXTURE_2D); gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); gl.glBindTexture(GL_TEXTURE_2D, textureID); gl.glColor3f(1, 1, 1); float[] color = new float[3]; float hRes = HEIGHT_RESOLUTION - 1; float stepSize = bounds.getWidth() / hRes; Coordinates pos = new Coordinates(); for (int x = 0; x < hRes; x++) { gl.glBegin(GL_TRIANGLE_STRIP); for (int y = 0; y <= hRes; y++) { for (int i = 0; i < 2; i++) { pos.setLatitude(bounds.getTop() + y * stepSize); pos.setLongitude(bounds.getLeft() + (x + i) * stepSize); gl.glMultiTexCoord2f( GL_TEXTURE0, (x + i) / (float) GRAIN_RESOLUTION, y / (float) GRAIN_RESOLUTION); gl.glMultiTexCoord2f(GL_TEXTURE1, (x + i) / hRes, y / hRes); float height = heights[x + HEIGHT_BORDER + i][y + HEIGHT_BORDER]; getHeightColor(color, height); float shade = getShade(x + i, y, stepSize); gl.glColor3f(color[0] * shade, color[1] * shade, color[2] * shade); gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), height); } } gl.glEnd(); } gl.glDisable(GL_TEXTURE_2D); gl.glActiveTexture(GL_TEXTURE0); renderPOIs(gl); gl.glEndList(); } }
public void frect(Coord c1, Coord c2, Coord c3, Coord c4) { glcolor(); texsel(-1); gl.glBegin(GL.GL_QUADS); vertex(c1); vertex(c2); vertex(c3); vertex(c4); gl.glEnd(); checkerr(); }
public void frect(Coord ul, Coord sz) { glcolor(); texsel(-1); gl.glBegin(GL.GL_QUADS); vertex(ul); vertex(ul.add(new Coord(sz.x, 0))); vertex(ul.add(sz)); vertex(ul.add(new Coord(0, sz.y))); gl.glEnd(); checkerr(); }
public void fire() throws IllegalActionException { if (_debugging) { _debug("Called fire()"); } GL gl = ((GRODirector) getDirector()).getGL(); gl.glBegin(GL.GL_QUADS); gl.glColor3f(0.3f, 0.7f, 0.3f); gl.glVertex3f(-1.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, 0.0f, -1.0f); gl.glVertex3f(-1.0f, 0.0f, -1.0f); gl.glEnd(); }
public void copyTex(GLTexture srcTex, GLTexture destTex) { float uscale = srcTex.getMaxTextureCoordS(); float vscale = srcTex.getMaxTextureCoordT(); float cx = 0.0f; float sx = +1.0f; if (destTex.isFlippedX()) { cx = 1.0f; sx = -1.0f; } float cy = 0.0f; float sy = +1.0f; if (destTex.isFlippedY()) { cy = 1.0f; sy = -1.0f; } gl.glEnable(srcTex.getTextureTarget()); gl.glActiveTexture(GL.GL_TEXTURE0); gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID()); pushFramebuffer(); setFramebuffer(FBO); FBO.setDrawBuffer(destTex.getTextureTarget(), destTex.getTextureID()); saveView(); setOrthographicView(destTex.width, destTex.height); gl.glEnable(srcTex.getTextureTarget()); gl.glActiveTexture(GL.GL_TEXTURE0); gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID()); gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 0.0f) * vscale); gl.glVertex2f(0.0f, 0.0f); gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 0.0f) * vscale); gl.glVertex2f(srcTex.width, 0.0f); gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 1.0f) * vscale); gl.glVertex2f(srcTex.width, srcTex.height); gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 1.0f) * vscale); gl.glVertex2f(0.0f, srcTex.height); gl.glEnd(); gl.glBindTexture(srcTex.getTextureTarget(), 0); restoreView(); popFramebuffer(); }
public void fellipse(Coord c, Coord r, int a1, int a2) { glcolor(); texsel(-1); gl.glBegin(GL.GL_TRIANGLE_FAN); vertex(c); for (int i = a1; i < a2; i += 5) { double a = (i * Math.PI * 2) / 360.0; vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y))); } double a = (a2 * Math.PI * 2) / 360.0; vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y))); gl.glEnd(); checkerr(); }
private void doDrawLines(Iterator<Vector> iter) { gl.glBegin(GL.GL_LINES); List<Vector> list = new ArrayList<Vector>(); for (Vector v : iterator(iter)) list.add(v); for (int i = 0; i != list.size(); ++i) { double x; double y; x = scaleX * (brushPos.getX() + list.get(i).getX()); y = scaleY * (brushPos.getY() + list.get(i).getY()); gl.glVertex3d(x, y, brushPos.getZ()); x = scaleX * (brushPos.getX() + list.get((i + 1) % list.size()).getX()); y = scaleY * (brushPos.getY() + list.get((i + 1) % list.size()).getY()); gl.glVertex3d(x, y, brushPos.getZ()); } gl.glEnd(); }
public void ftriangle(Coord center, int size) { if (size < 1) return; double sqrt3 = Math.sqrt(3); double Orad = (sqrt3 * size) / 3; double Irad = (sqrt3 * size) / 6; Coord c1, c2, c3; c1 = new Coord(center.x, center.y - (int) Orad); c2 = new Coord(center.x + (int) (size / 2) - 1, center.y + (int) Irad); c3 = new Coord(center.x - (int) (size / 2) + 1, center.y + (int) Irad); glcolor(); texsel(-1); gl.glBegin(GL.GL_TRIANGLE_STRIP); vertex(c1); vertex(c2); vertex(c3); gl.glEnd(); checkerr(); }
private static final void renderTriangles(final GL gl, final Geoset geoset) { gl.glBegin(GL.GL_TRIANGLES); for (int i = 0; i < geoset.getNbTriangles(); ++i) { final Triangle t = geoset.getTriangle(i); float[] v = t.getVertex(0).getData(); gl.glTexCoord2fv(v, Vertex.UV_OFFSET); gl.glVertex3fv(v, Vertex.POSITION_OFFSET); v = t.getVertex(1).getData(); gl.glTexCoord2fv(v, Vertex.UV_OFFSET); gl.glVertex3fv(v, Vertex.POSITION_OFFSET); v = t.getVertex(2).getData(); gl.glTexCoord2fv(v, Vertex.UV_OFFSET); gl.glVertex3fv(v, Vertex.POSITION_OFFSET); } gl.glEnd(); }
@Override public boolean renderizar(GL gl) { float[] cor2 = {cor.r, cor.g, cor.b, 1f}; gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, cor2, 0); gl.glPushMatrix(); { gl.glMultMatrixd(transformacao.getMatriz(), 0); gl.glBegin(primitiva); { for (Ponto ponto : pontos) { gl.glVertex3d(ponto.x, ponto.y, ponto.z); } } gl.glEnd(); this.bbox.draw(gl); } gl.glPopMatrix(); return super.renderizar(gl); }
public void draw(GL gl) { if (visible) { // Seta a cor da peça if (color != null) { float r = color.getR(); float g = color.getG(); float b = color.getB(); float a = color.getAlpha(); gl.glColor4f(r, g, b, a); } else { gl.glColor3d(Math.random(), Math.random(), Math.random()); } // desenha a peça gl.glBegin(drawType); for (Vetor3f v : points) { gl.glVertex3f(v.getX(), v.getY(), v.getZ()); } gl.glEnd(); } }
private void doDrawPolygon(Polygon polygon, int glMode) { if (glMode == GL.GL_LINES) { doDrawLines(polygon.getVertices()); } else { Iterator<Vector> vertices = polygon.getVertices(); Iterator<Vector> texCoords = null; if (textureCoords != null) texCoords = textureCoords.getVertices(); gl.glBegin(glMode); for (vertices.reset(); !vertices.isDone() && (currentTexture == null || !texCoords.isDone()); vertices.advance()) { Vector v = vertices.current(); if (currentTexture != null) { Vector texCoord = texCoords.current(); texCoords.advance(); double y = texCoord.getY(); if (currentTexture.getMustFlipVertically()) { y = currentTexture.getImageTexCoords().top() - y + currentTexture.getImageTexCoords().bottom(); } gl.glTexCoord2d(texCoord.getX(), y); } double x = scaleX * (brushPos.getX() + v.getX()); double y = scaleY * (brushPos.getY() + v.getY()); gl.glVertex3d(x, y, brushPos.getZ()); } gl.glEnd(); } }
private void renderOneside(Point2D a, Point2D b, GL gl, double d) { gl.glClear(0); Vector3D t = new Vector3D(b.x - a.x, 0, b.y - a.y); Vector3D n = new Vector3D(0, 1, 0); Vector3D cross = n.cross(t); gl.glNormal3d(cross.x, cross.y, cross.z); // Texture adjustment vars double length = scale * Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) / 100 + 0.1; double height = scale; // draw the 4 points of it gl.glBegin(GL.GL_POLYGON); gl.glTexCoord2d(0, 0); gl.glVertex3d(a.x, d, a.y); gl.glTexCoord2d(0, height); gl.glVertex3d(a.x, d + 100, a.y); gl.glTexCoord2d(length, height); gl.glVertex3d(b.x, d + 100, b.y); gl.glTexCoord2d(length, 0); gl.glVertex3d(b.x, d, b.y); gl.glEnd(); }
public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glClear(GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); // Front Of House gl.glBegin(GL.GL_QUADS); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glEnd(); // Front Left Window gl.glBegin(GL.GL_QUADS); gl.glColor3f(0.5f, 0.0f, 0.0f); gl.glVertex3f(-0.75f, 0.25f, 0.0f); gl.glVertex3f(-0.25f, 0.25f, 0.0f); gl.glVertex3f(-0.25f, 0.75f, 0.0f); gl.glVertex3f(-0.75f, 0.75f, 0.0f); gl.glEnd(); // Front Right Window gl.glBegin(GL.GL_QUADS); gl.glColor3f(0.5f, 0.0f, 0.0f); gl.glVertex3f(0.75f, 0.25f, 0.0f); gl.glVertex3f(0.25f, 0.25f, 0.0f); gl.glVertex3f(0.25f, 0.75f, 0.0f); gl.glVertex3f(0.75f, 0.75f, 0.0f); gl.glEnd(); // Door gl.glBegin(GL.GL_QUADS); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(-0.25f, -1.0f, 0.0f); gl.glVertex3f(0.25f, -1.0f, 0.0f); gl.glVertex3f(0.25f, -0.25f, 0.0f); gl.glVertex3f(-0.25f, -0.25f, 0.0f); gl.glEnd(); // Right Side of house gl.glBegin(GL.GL_QUADS); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(2.0f, -1.0f, -1.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Right Side of roof gl.glBegin(GL.GL_QUADS); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.75f, -1.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glEnd(); // Roof gl.glBegin(GL.GL_TRIANGLES); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Front Side Of House Outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glEnd(); // Right Side of house outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(2.0f, -1.0f, -1.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Roof Outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Right Side of roof Outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.75f, -1.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glEnd(); }
/** Here we actually draw the scene. */ public void display(GLAutoDrawable drawable) { super.display(drawable); System.out.println("GLScene - display"); GL gl = drawable.getGL(); try { // Update velocities and positions of all text float deltaT = 0.1f; Point2f tmp = new Point2f(); for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) { TextInfo info = (TextInfo) iter.next(); // Randomize things a little bit at run time if (random.nextInt(1000) == 0) { info.angularVelocity = INIT_ANG_VEL_MAG * (randomAngle() - 180); info.velocity = randomVelocity(INIT_VEL_MAG, INIT_VEL_MAG); } // Now update angles and positions info.angle += info.angularVelocity * deltaT; tmp.set(info.velocity); tmp.scale(deltaT); info.position.add(tmp); // Update color info.curTime += deltaT; if (info.curTime > 2 * Math.PI) { info.curTime -= 2 * Math.PI; } int rgb = Color.HSBtoRGB(info.h, (float) (0.5 * (1 + Math.sin(info.curTime)) * info.s), info.v); info.r = ((rgb >> 16) & 0xFF) / 255.0f; info.g = ((rgb >> 8) & 0xFF) / 255.0f; info.b = (rgb & 0xFF) / 255.0f; // Wrap angles and positions if (info.angle < 0) { info.angle += 360; } else if (info.angle > 360) { info.angle -= 360; } // Use maxTextWidth to avoid popping in/out at edges // Would be better to do oriented bounding rectangle computation if (info.position.x < -maxTextWidth) { info.position.x = info.position.x + glComposite.getCanvas().getWidth() + 2 * maxTextWidth; } else if (info.position.x > glComposite.getCanvas().getWidth() + maxTextWidth) { info.position.x = info.position.x - glComposite.getCanvas().getWidth() - 2 * maxTextWidth; } if (info.position.y < -maxTextWidth) { info.position.y = info.position.y + glComposite.getCanvas().getHeight() + 2 * maxTextWidth; } else if (info.position.y > glComposite.getCanvas().getHeight() + maxTextWidth) { info.position.y = info.position.y - glComposite.getCanvas().getHeight() - 2 * maxTextWidth; } } gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glComposite .getGLU() .gluOrtho2D( 0, glComposite.getCanvas().getWidth(), 0, glComposite.getCanvas().getHeight()); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); // Draw the background texture backgroundTexture.enable(); backgroundTexture.bind(); TextureCoords coords = backgroundTexture.getImageTexCoords(); int w = glComposite.getCanvas().getWidth(); int h = glComposite.getCanvas().getHeight(); float fw = w / 100.0f; float fh = h / 100.0f; gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(fw * coords.left(), fh * coords.bottom()); gl.glVertex3f(0, 0, 0); gl.glTexCoord2f(fw * coords.right(), fh * coords.bottom()); gl.glVertex3f(w, 0, 0); gl.glTexCoord2f(fw * coords.right(), fh * coords.top()); gl.glVertex3f(w, h, 0); gl.glTexCoord2f(fw * coords.left(), fh * coords.top()); gl.glVertex3f(0, h, 0); gl.glEnd(); backgroundTexture.disable(); // Render all text renderer.beginRendering(w, h); // Note we're doing some slightly fancy stuff to position the text. // We tell the text renderer to render the text at the origin, and // manipulate the modelview matrix to put the text where we want. gl.glMatrixMode(GL.GL_MODELVIEW); // First render drop shadows renderer.setColor(0, 0, 0, 0.5f); for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) { TextInfo info = (TextInfo) iter.next(); gl.glLoadIdentity(); gl.glTranslatef( info.position.x + dropShadowDistance, info.position.y - dropShadowDistance, 0); gl.glRotatef(info.angle, 0, 0, 1); renderer.draw(info.text, 0, 0); renderer.flush(); } // Now render the actual text for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) { TextInfo info = (TextInfo) iter.next(); gl.glLoadIdentity(); gl.glTranslatef(info.position.x, info.position.y, 0); gl.glRotatef(info.angle, 0, 0, 1); renderer.setColor(info.r, info.g, info.b, 1); renderer.draw(info.text, 0, 0); renderer.flush(); } renderer.endRendering(); } catch (Exception e) { e.printStackTrace(); } }
public void display(GLCanvas canvas) { GL gl = canvas.getGL(); // // render the simulation // try { sim.update(); } catch (Exception e) { Log.println("[Editor] exception in simulation update/calculate paths: " + e.getMessage()); e.printStackTrace(); } renderer.render(sim, canvas); // // render the grid // gl.glColor4f(0.4f, 0.4f, 0.4f, 0.4f); gl.glEnable(GL.GL_BLEND); gl.glBegin(GL.GL_LINES); for (int x = 0; x < 100; x++) { gl.glVertex2f( -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4, -50 * Constants.PLANET_MAX_SIZE * 4); gl.glVertex2f( -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4, 50 * Constants.PLANET_MAX_SIZE * 4); } for (int x = 0; x < 100; x++) { gl.glVertex2f( -50 * Constants.PLANET_MAX_SIZE * 4, -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4); gl.glVertex2f( +50 * Constants.PLANET_MAX_SIZE * 4, -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4); } gl.glDisable(GL.GL_BLEND); gl.glEnd(); // // render rectangle selection // if (drag_start != null && drag_end != null && selected_planets.size() == 0) { gl.glLineWidth(2); gl.glColor4f(1, 1, 1, 1); Widget.renderOutlinedQuad( drag_start.x, drag_start.y, drag_end.x - drag_start.x, -(drag_end.y - drag_start.y)); gl.glLineWidth(1); } // // render reference system // gl.glColor3f(1, 1, 1); gl.glBegin(GL.GL_LINES); gl.glColor3f(1, 0, 0); gl.glVertex2f(Constants.PLANET_MAX_SIZE * 50, 0); gl.glVertex2f(-Constants.PLANET_MAX_SIZE * 50, 0); gl.glColor3f(0, 1, 0); gl.glVertex2f(0, Constants.PLANET_MAX_SIZE * 50); gl.glVertex2f(0, -Constants.PLANET_MAX_SIZE * 50); gl.glEnd(); try { Thread.sleep(5); } catch (InterruptedException e) { } // // check mouse over planet // if (sim.getPlanet( renderer.getCamera().getScreenToWorldX(mouse_pos.x), renderer.getCamera().getScreenToWorldY(mouse_pos.y)) != null && !this.wasGuiIntersected(mouse_pos.x, mouse_pos.y) && drag_start != null) for (WorldAlignementContainer cont : conts) cont.setVisible(false); else for (WorldAlignementContainer cont : conts) cont.setVisible(true); }