private void drawSelectionHint(GLDrawContext gl) { if (this.currentSelectionAreaStart != null && this.currentSelectionAreaEnd != null) { if(selectionArea == null || !selectionArea.isValid()) { selectionArea = gl.generateGeometry(4, EGeometryFormatType.VertexOnly2D, true, "selection-area"); } if(updateSelectionArea) { updateSelectionArea(); try { gl.updateGeometryAt(selectionArea, 0, selectionAreaBuffer); } catch (IllegalBufferException e) { e.printStackTrace(); } updateSelectionArea = false; } try { gl.draw2D(selectionArea, null, EGeometryType.LineLoop, 0, 4, 0, 0, 0, 1, 1, 1, null, 1); } catch (IllegalBufferException e) { e.printStackTrace(); } } }
private static TextureHandle getTexture(GLDrawContext context) { if (texture == null || !texture.isValid()) { long startTime = System.currentTimeMillis(); short[] data; synchronized (preloadMutex) { if (preloadedTexture != null) { data = preloadedTexture; // free the array preloadedTexture = null; } else { data = getTexture(); } } ByteBuffer buffer = ByteBuffer.allocateDirect(data.length * 2).order(ByteOrder.nativeOrder()); buffer.asShortBuffer().put(data); texture = context.generateTexture(TEXTURE_SIZE, TEXTURE_SIZE, buffer.asShortBuffer(), "background"); System.out.println("Background texture generated in " + (System.currentTimeMillis() - startTime) + "ms"); } return texture; }
/** * Gets the text drawer to use. * * @param gl * The gl context to use as fallback * @param size * The font size * @return A text drawer. */ @Override public TextDrawer getTextDrawer(GLDrawContext gl, EFontSize size) { if (textDrawerFactory != null) { return textDrawerFactory.getTextDrawer(gl, size); } else { return gl.getTextDrawer(size); } }
@Override public void drawOnlyImageAt(GLDrawContext gl, float x, float y, float z, Color torsoColor, float fow) { try { if(nullGeometry == null || !nullGeometry.isValid()) nullGeometry = gl.storeGeometry(nullData, EGeometryFormatType.VertexOnly2D, false, "placeholder/null"); gl.draw2D(nullGeometry, null, EGeometryType.Quad, 0, 4, x, y, z, 1, 1, 1, null, NULL_IMAGE_ALPHA); gl.draw2D(nullGeometry, null, EGeometryType.LineLoop, 0, 4, x, y, z, 1, 1, 1, Color.RED, 1); } catch (IllegalBufferException e) { e.printStackTrace(); } }
private void generateGeometry(MapDrawContext context) throws IllegalBufferException { int vertices = bufferWidth*bufferHeight*3*2; shapeHandle = context.getGl().generateGeometry(vertices, EGeometryFormatType.Texture3D, false, "background-shape"); colorHandle = context.getGl().generateGeometry(vertices, EGeometryFormatType.ColorOnly, true, "background-color"); ByteBuffer shape_bfr = ByteBuffer.allocateDirect(BYTES_PER_FIELD_SHAPE*bufferWidth).order(ByteOrder.nativeOrder()); ByteBuffer color_bfr = ByteBuffer.allocateDirect(BYTES_PER_FIELD_COLOR*bufferWidth).order(ByteOrder.nativeOrder()); for(int y = 0;y != bufferHeight;y++) { for(int x = 0; x != bufferWidth;x++) { addTrianglesToGeometry(context, shape_bfr, x, y); } context.getGl().updateGeometryAt(shapeHandle, BYTES_PER_FIELD_SHAPE*bufferWidth*y, shape_bfr); shape_bfr.rewind(); } for(int y = 0;y != bufferHeight;y++) { int line_bfr4 = y*bufferWidth*4; for(int x = 0; x != bufferWidth;x++) { addColorTrianglesToGeometry(context, color_bfr, x, y, line_bfr4+x*4); } context.getGl().updateGeometryAt(colorHandle, BYTES_PER_FIELD_COLOR*bufferWidth*y, color_bfr); color_bfr.rewind(); } }
try { if(geometry == null || !geometry.isValid()) { geometry = context.storeGeometry( new float[] {0, 0, 0, 0, width, 0, 1, 0,(stride + 1) * width, height, 1, 1, stride * width, height, 0, 1,}, EGeometryFormatType.Texture2D, false, "minimap"); lineGeometry = context.generateGeometry(6, EGeometryFormatType.VertexOnly2D, true, "minimap-frame"); context.updateGeometryAt(lineGeometry, 0, lineBfr); imageWasCreatedJustNow = true; if (texture != null && texture.isValid()) { context.deleteTexture(texture); texture = null; texture = context.generateTexture(width, height, data, "minimap"); updatedLines.clear(); imageIsValid = true; currData.position(0); context.updateTexture(texture, 0, currLine, width, 1, currData ); context.draw2D(geometry, texture, EGeometryType.Quad, 0, 4, x, y, 0, 1, 1, 1, null, 1);
private void replaceGeometryValue(GLDrawContext context, int pos, float value) throws IllegalBufferException { bfr.rewind(); bfr.putFloat(value); context.updateGeometryAt(geometry, pos*4, bfr); }
private SharedGeometry(GLDrawContext dc, int index) { this.index = index; geometry = dc.generateGeometry(CAPACITY*4, EGeometryFormatType.Texture2D, true, "sharedgeometry-" + index); }
gl.updateGeometryAt(buildHandle, 0, buildBfr); gl.draw2D(buildHandle, texture, EGeometryType.Triangle, 0, 3, left, top, 0, 1, 1, 1, null, color); } catch (IllegalBufferException e) { handleIllegalBufferException(e);
@Override public void drawAt(GLDrawContext gl) { super.drawAt(gl); TextDrawer drawer = gl.getTextDrawer(EFontSize.NORMAL); float textHeight = drawer.getHeight(inputString.toString() + "X"); float y = getPosition().getCenterY() - textHeight / 2; float x = getPosition().getMinX() + 2; drawer.drawString(x, y, inputString.toString()); if(geometry == null || !geometry.isValid()) geometry = gl.storeGeometry(new float[] {0, 0, 0, 1}, EGeometryFormatType.VertexOnly2D, false, "uiinput-line"); float carretX = x + drawer.getWidth(inputString.substring(0, carret) + "X") - drawer.getWidth("X"); try { gl.draw2D(geometry, null, EGeometryType.LineStrip, 0, 2, carretX, y, 0, 0, textHeight, 0, null, 1); } catch (IllegalBufferException e) { e.printStackTrace(); } }
private void drawViewMark(GLDrawContext context, float x, float y) { try { context.draw2D(lineGeometry, null, EGeometryType.LineLoop, 0, 6, x, y, 0, 1, 1, 1, null, 1); } catch (IllegalBufferException e) { e.printStackTrace(); } }
useFloatColors = (context.getGl() instanceof GL2DrawContext); generateGeometry(context); context.getGl().setHeightMatrix(context.getConverter().getMatrixWithHeight()); gl.drawTrianglesWithTextureColored(getTexture(context.getGl()), shapeHandle, colorHandle, offset*2, screenArea.getHeight(), screenArea.getWidth()*2, draw_stride, x, y);
/** * Begin a new draw session (=> draw a new image). Sets up the gl screen assuming the current viewport is set to (0,0,width,height) * * @param gl2 * The gl context to use. * @see #end() */ public void begin(GLDrawContext gl2) { this.gl = gl2; // beginTime = System.nanoTime(); float zoom = screen.getZoom(); gl2.setGlobalAttributes(0, 0, 0, zoom, zoom, 1); offsetX = (int) (-screen.getLeft()+.5f); offsetY = (int) (-screen.getBottom()+.5f); }
/** * Checks if this buffer is valid. * * @return <code>true</code> if the buffer is valid and can be used. */ public boolean isValid() { return dc.isValid(); }
/** * Gets the texture handle. * * @param gl * The gl context to use when creating the texutre. * @return A valid texture handle. */ public TextureHandle getTexture(GLDrawContext gl) { if (!textureValid || !texture.isValid()) { if (texture != null) { gl.deleteTexture(texture); } try { loadTexture(gl); } catch (IOException e) { e.printStackTrace(); } } return texture; }
private void updateMapType(MapDrawContext context, int x, int y) throws IllegalBufferException { int bfr_pos = y*bufferWidth+x; if(mapInvalid.get(bfr_pos)) { mapInvalid.clear(bfr_pos); shape_update_bfr.rewind(); addTrianglesToGeometry(context, shape_update_bfr, x, y); context.getGl().updateGeometryAt(shapeHandle, bfr_pos * BYTES_PER_FIELD_SHAPE, shape_update_bfr); } }
private void validate(GLDrawContext dc) { if(!geometry.isValid()) { geometry = dc.generateGeometry(CAPACITY*4, EGeometryFormatType.Texture2D, true, "sharedgeometry-" + index); size = 0; } }
@Override public void drawOnlyImageAt(GLDrawContext gl, float x, float y, float z, Color torsoColor, float fow) { try { checkHandles(gl); gl.draw2D(geometryIndex.geometry, texture, EGeometryType.Quad, geometryIndex.index, 4, x, y, z, 1, 1, 1, null, 1); } catch (IllegalBufferException e) { handleIllegalBufferException(e); } }
private void drawDebugColors() { GLDrawContext gl = this.context.getGl(); if(shapeHandle == null || !shapeHandle.isValid()) shapeHandle = gl.storeGeometry(shape, EGeometryFormatType.VertexOnly2D, false, "debugshape"); int drawX = context.getOffsetX(); int drawY = context.getOffsetY(); context.getScreenArea().stream().filterBounds(width, height).forEach((x, y) -> { try { int argb = map.getDebugColorAt(x, y, debugColorMode); if (argb != 0) { int height = context.getHeight(x, y); float dx = drawX+context.getConverter().getViewX(x, y, height); float dy = drawY+context.getConverter().getViewY(x, y, height); gl.draw2D(shapeHandle, null, EGeometryType.Quad, 0, 4, dx, dy, .5f, 1, 1, 1, Color.fromShort((short) argb), 1); } } catch (IllegalBufferException e) { // TODO: Create a crash report // This should never happen since we only use texture 0 (no texture) } }); }
gl.setGlobalAttributes(0, 0, UI_OVERLAY_Z, 1, 1, 1); drawSelectionHint(gl); controls.drawAt(gl);