List of usage examples for com.badlogic.gdx.graphics.glutils ShapeRenderer setColor
public void setColor(Color color)
From source file:releasethekraken.ui.tooltip.PurchaseUnitToolTip.java
@Override public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) { super.renderShapes(shapeRenderer, delta, runTime); if (this.visible) { //The mouse coordinates float mouseX = Gdx.input.getX(0); float mouseY = Gdx.input.getY(0); float textHeight = GameAssets.fontMain.getCapHeight(); float boxWidth = (0.25F + 0.005F) * Gdx.graphics.getWidth(); float boxHeight = this.descriptionHeight + GameAssets.fontMain.getCapHeight() + 0.16F * Gdx.graphics.getHeight(); float boxX = mouseX + 0.05F * Gdx.graphics.getWidth(); float boxY = Gdx.graphics.getHeight() - mouseY + (boxHeight - textHeight) / 2 + textHeight / 2; float triangleAlignX = boxX; /*/*from w ww.j a v a 2s . co m*/ Starting and stopping the shape renderer multiple times and copying colors might have an impact on performance. We might want to find a more efficient way of doing this. Maybe tooltips get their own render pass? */ shapeRenderer.end(); //End the shape batch, drawing everything it has so far //Enable OpenGL alpha blending Gdx.gl.glEnable(Gdx.gl.GL_BLEND); Gdx.gl.glBlendFunc(Gdx.gl.GL_SRC_ALPHA, Gdx.gl.GL_ONE_MINUS_SRC_ALPHA); //Start a new shape batch shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); //Render tooltip background shapeRenderer.setColor(this.color.cpy().sub(0, 0, 0, 0.35F)); //Make the color transparent shapeRenderer.rect(boxX, boxY - boxHeight, boxWidth, boxHeight); //Tooltip background shapeRenderer.triangle(mouseX, Gdx.graphics.getHeight() - mouseY, triangleAlignX, boxY, triangleAlignX, boxY - boxHeight); //Triangle part shapeRenderer.end(); //End the shape batch, drawing the transparent tooltip //Disable OpenGL blending so everything else doesn't get messed up Gdx.gl.glDisable(Gdx.gl.GL_BLEND); //Start a new shape batch so that it is left in the state it started in shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); } }
From source file:releasethekraken.ui.tooltip.TextToolTip.java
@Override public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) //TODO: Make tool tip display better { super.renderShapes(shapeRenderer, delta, runTime); if (this.visible) { //The mouse coordinates float mouseX = Gdx.input.getX(0); float mouseY = Gdx.input.getY(0); float textHeight = GameAssets.fontMain.getCapHeight(); float textWidth = GameAssets.fontMain.getSpaceWidth() * this.text.length(); float boxWidth = textWidth; float boxHeight = textHeight * 1.8F; float boxX = mouseX + 0.05F * Gdx.graphics.getWidth(); float boxY = Gdx.graphics.getHeight() - mouseY + (boxHeight - textHeight) / 2 + textHeight / 2; float triangleAlignX = boxX; //Swap the tooltip to the other side if it's on the other side of the screen if (mouseX > Gdx.graphics.getWidth() / 2) { boxX = mouseX - 0.05F * Gdx.graphics.getWidth() - textWidth; triangleAlignX = boxX + boxWidth; }//from w ww. j av a 2s . c o m /* Starting and stopping the shape renderer multiple times and copying colors might have an impact on performance. We might want to find a more efficient way of doing this. Maybe tooltips get their own render pass? */ shapeRenderer.end(); //End the shape batch, drawing everything it has so far //Enable OpenGL alpha blending Gdx.gl.glEnable(Gdx.gl.GL_BLEND); Gdx.gl.glBlendFunc(Gdx.gl.GL_SRC_ALPHA, Gdx.gl.GL_ONE_MINUS_SRC_ALPHA); //Start a new shape batch shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); //Render tooltip background shapeRenderer.setColor(this.color.cpy().sub(0, 0, 0, 0.35F)); //Make the color transparent shapeRenderer.rect(boxX, boxY - boxHeight, boxWidth, boxHeight); //Tooltip background shapeRenderer.triangle(mouseX, Gdx.graphics.getHeight() - mouseY, triangleAlignX, boxY, triangleAlignX, boxY - boxHeight); //Triangle part shapeRenderer.end(); //End the shape batch, drawing the transparent tooltip //Disable OpenGL blending so everything else doesn't get messed up Gdx.gl.glDisable(Gdx.gl.GL_BLEND); //Start a new shape batch so that it is left in the state it started in shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); } }
From source file:releasethekraken.ui.UiButton.java
@Override public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) { super.renderShapes(shapeRenderer, delta, runTime); float borderWidth = 0.0025F * Gdx.graphics.getWidth(); shapeRenderer.setColor(this.defaultColors[0][this.currentColorIndex]); shapeRenderer.rect(this.x, this.y, this.width, this.height); //Background shapeRenderer.setColor(this.defaultColors[1][this.currentColorIndex]); shapeRenderer.rect(this.x, this.y + this.height / 2, this.width - this.height / 2, this.height / 2); //Render middle rectangle shapeRenderer.triangle(this.x + this.width, this.y + this.height, this.x + this.width - this.height / 2, this.y + this.height / 2, this.x + this.width - this.height / 2, this.y + this.height); //render middle right triangle shapeRenderer.triangle(this.x, this.y, this.x, this.y + this.height / 2, this.x + this.height / 2, this.y + this.height / 2); //render middle left triangle shapeRenderer.setColor(this.defaultColors[2][this.currentColorIndex]); shapeRenderer.rect(this.x + borderWidth, this.y + borderWidth, this.width - borderWidth * 2, this.height - borderWidth * 2); //Inner box }
From source file:releasethekraken.ui.UiPointsBar.java
@Override public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) { super.renderShapes(shapeRenderer, delta, runTime); //Draw background shapeRenderer.setColor(Color.LIGHT_GRAY); shapeRenderer.rect(this.x, this.y, this.width, this.height); float barValue = this.value / (this.max * 1F); float barWidth = this.width * barValue; barWidth = MathUtils.clamp(barWidth, 0, this.width); //Draw points bar final Color barColor = Color.valueOf("FF8800"); shapeRenderer.setColor(barColor);//from w w w . j av a 2 s . c om shapeRenderer.rect(this.x, this.y, barWidth, this.height); }
From source file:sg.atom2d.game2d.graphics.anim.spine.skeleton.SkeletonRendererDebug.java
License:Open Source License
public void draw(Skeleton skeleton) { float skeletonX = skeleton.getX(); float skeletonY = skeleton.getY(); Gdx.gl.glEnable(GL10.GL_BLEND);/*from w ww . java2 s . c o m*/ ShapeRenderer renderer = this.renderer; renderer.begin(ShapeType.Line); Array<Bone> bones = skeleton.getBones(); if (drawBones) { renderer.setColor(boneLineColor); for (int i = 0, n = bones.size; i < n; i++) { Bone bone = bones.get(i); if (bone.parent == null) continue; float x = skeletonX + bone.data.length * bone.m00 + bone.worldX; float y = skeletonY + bone.data.length * bone.m10 + bone.worldY; renderer.line(skeletonX + bone.worldX, skeletonY + bone.worldY, x, y); } } if (drawRegionAttachments) { renderer.setColor(regionAttachmentLineColor); Array<Slot> slots = skeleton.getSlots(); for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment) attachment; regionAttachment.updateWorldVertices(slot, false); float[] vertices = regionAttachment.getWorldVertices(); renderer.line(vertices[X1], vertices[Y1], vertices[X2], vertices[Y2]); renderer.line(vertices[X2], vertices[Y2], vertices[X3], vertices[Y3]); renderer.line(vertices[X3], vertices[Y3], vertices[X4], vertices[Y4]); renderer.line(vertices[X4], vertices[Y4], vertices[X1], vertices[Y1]); } } } if (drawBoundingBoxes) { SkeletonBounds bounds = this.bounds; bounds.update(skeleton, true); renderer.setColor(aabbColor); renderer.rect(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()); renderer.setColor(boundingBoxColor); Array<FloatArray> polygons = bounds.getPolygons(); for (int i = 0, n = polygons.size; i < n; i++) { FloatArray polygon = polygons.get(i); renderer.polygon(polygon.items, 0, polygon.size); } } renderer.end(); renderer.begin(ShapeType.Filled); if (drawBones) { renderer.setColor(boneOriginColor); for (int i = 0, n = bones.size; i < n; i++) { Bone bone = bones.get(i); renderer.setColor(ColorRGBA.GREEN); renderer.circle(skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * scale); } } renderer.end(); }
From source file:spaceisnear.game.ui.TextField.java
@Override public void paint(Batch batch) { if (checkKeys(keycode)) { keycode = 0;/*from w ww . j a v a 2 s . com*/ } ShapeRenderer renderer = getRenderer(); focused = getStage().getKeyboardFocus() == this; int start = 0; int end = text.length(); int startingXText = 0; //TODO GlyphLayout glyphLayout = new GlyphLayout(font, text); if (glyphLayout.width > getWidthWithoutPaddings()) { end = text.length(); start = end - 1; glyphLayout.setText(font, text, start, end, textColor, getWidthWithoutPaddings(), 0, false, null); while (start > 0 && glyphLayout.width < getWidthWithoutPaddings()) { start--; } glyphLayout.setText(font, text, 0, start, textColor, getWidthWithoutPaddings(), 0, false, null); startingXText = (int) -glyphLayout.width; } // { Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); renderer.setProjectionMatrix(batch.getProjectionMatrix()); renderer.begin(ShapeRenderer.ShapeType.Filled); renderer.setColor(backgroundColor); renderer.rect(0, 0, getWidth(), getHeight()); renderer.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } { renderer.begin(ShapeRenderer.ShapeType.Line); renderer.setColor(borderColor); renderer.rect(0, 0, getWidth() + 1, getHeight()); renderer.end(); } //cursor renderer.begin(ShapeRenderer.ShapeType.Line); font.setColor(Color.BLACK); if (focused) { glyphLayout.setText(font, text, 0, currentPosition, textColor, getWidthWithoutPaddings(), 0, false, null); final float x = 10 + glyphLayout.width + startingXText; renderer.line(x, 3, x, font.getLineHeight() + 2); renderer.line(x + 1, 3, x + 1, font.getLineHeight() + 2); } renderer.end(); batch.begin(); font.setColor(Color.BLACK); font.draw(batch, text.subSequence(start, end), WIDTH_PADDING + getX(), 3 + getY()); batch.end(); }
From source file:spine.SkeletonRendererDebug.java
License:Open Source License
public void draw(Skeleton skeleton) { float skeletonX = skeleton.getX(); float skeletonY = skeleton.getY(); Gdx.gl.glEnable(GL20.GL_BLEND);//from w w w. j a va 2 s. com int srcFunc = premultipliedAlpha ? GL20.GL_ONE : GL20.GL_SRC_ALPHA; Gdx.gl.glBlendFunc(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA); ShapeRenderer shapes = this.shapes; Array<Bone> bones = skeleton.getBones(); if (drawBones) { shapes.setColor(boneLineColor); shapes.begin(ShapeType.Filled); for (int i = 0, n = bones.size; i < n; i++) { Bone bone = bones.get(i); if (bone.parent == null) continue; float x = skeletonX + bone.data.length * bone.a + bone.worldX; float y = skeletonY + bone.data.length * bone.c + bone.worldY; shapes.rectLine(skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, boneWidth * scale); } shapes.end(); shapes.begin(ShapeType.Line); shapes.x(skeletonX, skeletonY, 4 * scale); } else shapes.begin(ShapeType.Line); if (drawRegionAttachments) { shapes.setColor(attachmentLineColor); Array<Slot> slots = skeleton.getSlots(); for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment) attachment; float[] vertices = regionAttachment.updateWorldVertices(slot, false); shapes.line(vertices[X1], vertices[Y1], vertices[X2], vertices[Y2]); shapes.line(vertices[X2], vertices[Y2], vertices[X3], vertices[Y3]); shapes.line(vertices[X3], vertices[Y3], vertices[X4], vertices[Y4]); shapes.line(vertices[X4], vertices[Y4], vertices[X1], vertices[Y1]); } } } if (drawMeshHull || drawMeshTriangles) { Array<Slot> slots = skeleton.getSlots(); for (int i = 0, n = slots.size; i < n; i++) { Slot slot = slots.get(i); Attachment attachment = slot.attachment; float[] vertices = null; short[] triangles = null; int hullLength = 0; if (attachment instanceof MeshAttachment) { MeshAttachment mesh = (MeshAttachment) attachment; mesh.updateWorldVertices(slot, false); vertices = mesh.getWorldVertices(); triangles = mesh.getTriangles(); hullLength = mesh.getHullLength(); } else if (attachment instanceof SkinnedMeshAttachment) { SkinnedMeshAttachment mesh = (SkinnedMeshAttachment) attachment; mesh.updateWorldVertices(slot, false); vertices = mesh.getWorldVertices(); triangles = mesh.getTriangles(); hullLength = mesh.getHullLength(); } if (vertices == null || triangles == null) continue; if (drawMeshTriangles) { shapes.setColor(triangleLineColor); for (int ii = 0, nn = triangles.length; ii < nn; ii += 3) { int v1 = triangles[ii] * 5, v2 = triangles[ii + 1] * 5, v3 = triangles[ii + 2] * 5; shapes.triangle(vertices[v1], vertices[v1 + 1], // vertices[v2], vertices[v2 + 1], // vertices[v3], vertices[v3 + 1] // ); } } if (drawMeshHull && hullLength > 0) { shapes.setColor(attachmentLineColor); hullLength = hullLength / 2 * 5; float lastX = vertices[hullLength - 5], lastY = vertices[hullLength - 4]; for (int ii = 0, nn = hullLength; ii < nn; ii += 5) { float x = vertices[ii], y = vertices[ii + 1]; shapes.line(x, y, lastX, lastY); lastX = x; lastY = y; } } } } if (drawBoundingBoxes) { SkeletonBounds bounds = this.bounds; bounds.update(skeleton, true); shapes.setColor(aabbColor); shapes.rect(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()); shapes.setColor(boundingBoxColor); Array<FloatArray> polygons = bounds.getPolygons(); for (int i = 0, n = polygons.size; i < n; i++) { FloatArray polygon = polygons.get(i); shapes.polygon(polygon.items, 0, polygon.size); } } shapes.end(); shapes.begin(ShapeType.Filled); if (drawBones) { shapes.setColor(boneOriginColor); for (int i = 0, n = bones.size; i < n; i++) { Bone bone = bones.get(i); shapes.setColor(Color.GREEN); shapes.circle(skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * scale, 8); } } shapes.end(); }
From source file:us.thirdmillenium.strategicassaultsimulator.environment.GameEnvironment.java
License:Apache License
@Override public void simulate(float deltaTime) { // Compute time delta (max of frame speed) deltaTime = (float) Math.min(deltaTime, 1 / Params.FramesPerSecond); if (DRAW) {//w ww . j av a 2s .c o m // Clear Background Gdx.gl.glClearColor(1, 0, 0, 1); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Draw Map this.Camera.update(); this.TiledMapRenderer.setView(this.Camera); this.TiledMapRenderer.render(); } // Test if Bullets Intersected with Anything MapObjects wallMapObjects = this.TiledMap.getLayers().get(2).getObjects(); Iterator<GreenBullet> bullets = this.BulletTracker.iterator(); this.SpriteBatchRenderer.setProjectionMatrix(this.Camera.combined); this.SpriteBatchRenderer.begin(); while (bullets.hasNext()) { // Collect a Bullet to consider GreenBullet currentBullet = bullets.next(); if (DRAW) { currentBullet.drawSprite(this.SpriteBatchRenderer); } currentBullet.updateBullet(deltaTime); // If bullet is off-screen, remove it. if (currentBullet.getBulletVector().x < 0 || currentBullet.getBulletVector().x > this.width || currentBullet.getBulletVector().y < 0 || currentBullet.getBulletVector().y > this.height) { this.BulletTracker.remove(currentBullet); } else { // Compare with all Agents Rectangle agentBound; Iterator<AgentModel> shootItr = this.shooters.iterator(); while (shootItr.hasNext()) { AgentModel currShooter = shootItr.next(); if (!currentBullet.thisAgentShotMe(currShooter) && Intersector.overlapConvexPolygons( GraphicsHelpers.convertRectangleToPolygon(currShooter.getBoundingRectangle()), currentBullet.getBulletPath())) { currShooter.agentHit(); this.BulletTracker.remove(currentBullet); } } Iterator<AgentModel> agentItr = this.trainees.iterator(); while (agentItr.hasNext()) { AgentModel currAgent = agentItr.next(); if (!currentBullet.thisAgentShotMe(currAgent) && Intersector.overlapConvexPolygons( GraphicsHelpers.convertRectangleToPolygon(currAgent.getBoundingRectangle()), currentBullet.getBulletPath())) { currAgent.agentHit(); this.BulletTracker.remove(currentBullet); } } // Compare with all Wall Boundaries for (int i = 0; i < wallMapObjects.getCount(); i++) { Object rectangleMapObject = wallMapObjects.get(i); // Make sure this is a Rectangle from Tiled describing a wall. if (rectangleMapObject.getClass() == RectangleMapObject.class) { Rectangle wallRectangle = ((RectangleMapObject) rectangleMapObject).getRectangle(); Polygon polyBound = GraphicsHelpers.convertRectangleToPolygon(wallRectangle); // Terminate when hitting a wall if (Intersector.overlapConvexPolygons(polyBound, currentBullet.getBulletPath())) { this.BulletTracker.remove(currentBullet); } } } } } this.SpriteBatchRenderer.end(); // Draw DEBUG information if (DEBUG && DRAW) { // Draw Map Nodes /*this.MapNodeSR.setProjectionMatrix(this.Camera.combined); this.MapNodeSR.setColor(Color.OLIVE); this.MapNodeSR.begin(ShapeRenderer.ShapeType.Filled); if (this.TraverseNodes != null) { for (Integer key : this.TraverseNodes.keySet()) { this.MapNodeSR.circle(this.TraverseNodes.get(key).getPixelX(), this.TraverseNodes.get(key).getPixelY(), 10); } } this.MapNodeSR.end();*/ // Draw Overlay Lines this.LineRenderer.setProjectionMatrix(this.Camera.combined); this.LineRenderer.begin(ShapeRenderer.ShapeType.Filled); // For each Agent. Different Colors? this.LineRenderer.setColor(Color.BLACK); /*if( PUPPET ) { this.puppet.drawPath(this.LineRenderer); }*/ Iterator<AgentModel> agentItr = this.trainees.iterator(); while (agentItr.hasNext()) { AgentModel currAgent = agentItr.next(); currAgent.drawPath(this.LineRenderer); } this.LineRenderer.end(); } // Draw Agent Sprites this.SpriteBatchRenderer.begin(); /*if( PUPPET ) { this.puppet.updateAgent(deltaTime); this.puppet.drawAgent(this.SpriteBatchRenderer); }*/ Iterator<AgentModel> shootItr = this.shooters.iterator(); while (shootItr.hasNext()) { AgentModel currShooter = shootItr.next(); currShooter.updateAgent(deltaTime); if (DRAW) { currShooter.drawAgent(this.SpriteBatchRenderer); } } Iterator<AgentModel> agentItr = this.trainees.iterator(); while (agentItr.hasNext()) { AgentModel currAgent = agentItr.next(); currAgent.updateAgent(deltaTime); if (DRAW) { currAgent.drawAgent(this.SpriteBatchRenderer); } } this.SpriteBatchRenderer.end(); if (DEBUG) { Iterator<AgentModel> agentItr2 = this.trainees.iterator(); ShapeRenderer visionCone = new ShapeRenderer(); visionCone.setProjectionMatrix(this.Camera.combined); visionCone.begin(ShapeRenderer.ShapeType.Line); visionCone.setColor(Color.YELLOW); while (agentItr2.hasNext()) { AgentModel currAgent = agentItr2.next(); currAgent.drawVision(visionCone); } visionCone.end(); } /*// Test Draw the Collision Boxes if( DEBUG && DRAW ) { ShapeRenderer anotherShapeRenderer = new ShapeRenderer(); anotherShapeRenderer.setProjectionMatrix(this.Camera.combined); anotherShapeRenderer.begin(ShapeRenderer.ShapeType.Line); bullets = this.BulletTracker.iterator(); while(bullets.hasNext()) { GreenBullet currentBullet = bullets.next(); anotherShapeRenderer.polygon(currentBullet.getBulletPath().getTransformedVertices()); } for(int i = 0; i < wallMapObjects.getCount(); i++ ){ Object obj = wallMapObjects.get(i); if( obj.getClass() == RectangleMapObject.class ) { Rectangle boundary = ((RectangleMapObject)obj).getRectangle(); anotherShapeRenderer.rect(boundary.x, boundary.y, boundary.width, boundary.height); float[] vertices = { boundary.x, boundary.y, boundary.x + boundary.width, boundary.y, boundary.x + boundary.width, boundary.y + boundary.height, boundary.x, boundary.y + boundary.height }; //Polygon polyBound = new Polygon(vertices); anotherShapeRenderer.setColor(Color.BLUE); anotherShapeRenderer.polygon(vertices); } } anotherShapeRenderer.end(); }*/ }
From source file:vault.clockwork.actors.ButtonActor.java
License:Open Source License
@Override public void debug(ShapeRenderer gizmo) { Rectangle rect = spr.getBoundingRectangle(); gizmo.setColor(Color.MAGENTA); gizmo.begin(ShapeRenderer.ShapeType.Line); gizmo.rect(rect.x, rect.y, rect.width, rect.height); gizmo.end();//from w w w . j a va2 s . c o m }
From source file:vault.clockwork.editor.props.GroundProp.java
License:Open Source License
/** * Draw the turret radius as bounds.//from w w w . j a va 2 s. c o m * @param gizmo */ @Override public void draw(ShapeRenderer gizmo) { gizmo.setColor(Color.YELLOW); gizmo.rect(-100.f * Physics.SCALE_INV, -2.f * Physics.SCALE_INV, 200.f * Physics.SCALE_INV, .4f * Physics.SCALE_INV); }