List of usage examples for com.badlogic.gdx.graphics GL20 GL_SRC_ALPHA
int GL_SRC_ALPHA
To view the source code for com.badlogic.gdx.graphics GL20 GL_SRC_ALPHA.
Click Source Link
From source file:seventh.client.gfx.GdxCanvas.java
License:Open Source License
@Override public void fillArc(float x, float y, float radius, float start, float degrees, Integer color) { Color c = setTempColor(color); Gdx.gl.glEnable(GL20.GL_BLEND);//from w w w . jav a2s . com Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); this.shapes.setColor(c); this.shapes.begin(ShapeType.Filled); this.shapes.arc(x, y, radius, start, degrees); this.shapes.end(); Gdx.gl.glDisable(GL20.GL_BLEND); }
From source file:spaceisnear.game.ui.TextField.java
@Override public void paint(Batch batch) { if (checkKeys(keycode)) { keycode = 0;//from w ww . ja v a 2s . c o m } 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 v a 2 s . co m 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:ta.firegreen.creation.creator.java
License:Apache License
@Override public void create() { batch = new SpriteBatch(); rendu = new ImmediateModeRenderer20(false, true, 0); renduTexture = new ImmediateModeRenderer20(false, true, 1); configF = new ConfigurationFrame(this); cam = new PerspectiveCamera(95, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D); Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST); Gdx.gl20.glEnable(GL20.GL_BLEND);/* w w w . j ava2 s. c om*/ Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); shape = new ShapeRenderer(); cam.near = 1; cam.far = 100; cam.direction.set(0, 1, 0); cam.position.set(posX, posY, posZ); cam.lookAt(cibleX, cibleY, cibleZ); cam.update(); configF.setVisible(true); trianglesSelected = new MeshTA(); }
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) {/*from w ww. j a v a2s .com*/ // 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.controllers.CameraController.java
License:Open Source License
/** * Wykonuje sie przed rysowaniem debug screena. * @param gizmo // www . j a v a 2 s.c om */ @Override public void preDebug(ShapeRenderer gizmo) { gizmo.setProjectionMatrix(camera.combined); // enable alpha channel usage Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); // draw scene regions gizmo.begin(ShapeRenderer.ShapeType.Line); gizmo.setColor(1.f, 0.1f, 0.f, 0.5f); gizmo.rect(CameraController.SCREEN_BOUNDS.x, CameraController.SCREEN_BOUNDS.y, CameraController.SCREEN_BOUNDS.width, CameraController.SCREEN_BOUNDS.height); gizmo.end(); }
From source file:vault.clockwork.editor.gui.GUIFieldElement.java
License:Open Source License
/** * Draw the field input.// w w w .j a v a 2 s. c o m * @param shape * @param batch */ @Override public void draw(ShapeRenderer shape, SpriteBatch batch) { text = value + (focused && ticks % 20 > 10 ? "|" : ""); if (focused) { ticks++; } // calculate label text bounds Rectangle bounds = getBounds(); // enable alpha channel usage Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); // draw the shape shape.begin(ShapeRenderer.ShapeType.Filled); shape.setColor(0, 0, 0, .5f); shape.rect(bounds.x - 2, bounds.y - 2, bounds.width + 4, bounds.height + 4); shape.end(); // draw the label batch.begin(); { font.setColor(!focused ? (overed ? Color.PINK : Color.WHITE) : Color.RED); font.draw(batch, field.getName() + ": " + text, bounds.x, bounds.y + bounds.height); } batch.end(); }
From source file:vault.clockwork.editor.gui.GUILabelElement.java
License:Open Source License
/** * Draw the label.// ww w .j a va 2 s . c om * @param shape * @param batch */ @Override public void draw(ShapeRenderer shape, SpriteBatch batch) { // calculate label text bounds Rectangle bounds = getBounds(); // enable alpha channel usage Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); // draw the shape shape.begin(ShapeRenderer.ShapeType.Filled); shape.setColor(0, 0, 0, .5f); shape.rect(bounds.x - 2, bounds.y - 2, bounds.width + 4, bounds.height + 4); shape.end(); // draw the label batch.begin(); { font.setColor(!focused ? (overed ? Color.PINK : Color.WHITE) : Color.RED); font.draw(batch, text, bounds.x, bounds.y + bounds.height); } batch.end(); }
From source file:vault.clockwork.system.Console.java
License:Open Source License
/** * Render the console.//from ww w . ja va 2s.co m * @see System#postPerform() */ @Override public void postPerform() { if (!visible) { return; } float scwidth = (float) Gdx.graphics.getWidth(), scheight = (float) Gdx.graphics.getHeight(); // assign projection to the renderers Matrix4 ortho = new Matrix4().setToOrtho2D(0.f, 0.f, scwidth, scheight); renderer.setProjectionMatrix(ortho); batch.setProjectionMatrix(ortho); // draw the console background Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); renderer.begin(ShapeRenderer.ShapeType.Filled); renderer.setColor(color); renderer.rect(0.f, scheight - height, scwidth, height); renderer.end(); // crop the logs list while (logs.size > (int) (height / 19.f) - 1) { logs.removeIndex(0); } // draw the console logs batch.begin(); for (int i = 0; i < logs.size; i++) { font.draw(batch, logs.get(logs.size - i - 1), 5.f, scheight - height + 25.f + 19.f * (i + 1)); } font.draw(batch, input + ((tickness % 30 < 15) ? "|" : ""), 5.f, scheight - height + 25.f); batch.end(); }
From source file:ve.ucv.ciens.ccg.nxtar.NxtARCore.java
License:Apache License
/** * <p>Initialize the member fields and launch the networking threads. Also creates and * sets the application states.</p> *///w w w . j ava 2 s. co m public void create() { try { ScenarioGlobals.init(this); } catch (IllegalArgumentException e) { Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument initializing globals: ", e); System.exit(1); return; } catch (InstantiationException e) { Gdx.app.error(TAG, CLASS_NAME + ".create(): Instantiation exception initializing globals: ", e); System.exit(1); return; } catch (IllegalAccessException e) { Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal access exception initializing globals: ", e); System.exit(1); return; } // Set up rendering fields and settings. batch = new SpriteBatch(); batch.enableBlending(); batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); ShaderProgram.pedantic = false; // Create the state objects. states = new BaseState[game_states_t.getNumStates()]; try { if (Ouya.runningOnOuya) states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this); else states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this); try { states[game_states_t.IN_GAME.getValue()] = new InGameState(this); } catch (IllegalStateException e) { Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in IN_GAME_STATE: ", e); System.exit(1); return; } states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this); try { states[game_states_t.AUTOMATIC_ACTION.getValue()] = new AutomaticActionState(this); } catch (IllegalStateException e) { Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in AUTOMATIC_ACTION_STATE: ", e); System.exit(1); return; } states[game_states_t.AUTOMATIC_ACTION_SUMMARY.getValue()] = new AutomaticActionSummaryState(this); states[game_states_t.SCENARIO_END_SUMMARY.getValue()] = new ScenarioEndSummaryState(this); states[game_states_t.HINTS.getValue()] = new InstructionsState(this); } catch (IllegalArgumentException e) { Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e); System.exit(1); return; } // Register controller listeners. for (BaseState state : states) { Controllers.addListener(state); } // Set up the overlay font. overlayX = -(Utils.getScreenWidthWithOverscan() / 2) + 10; overlayY = (Utils.getScreenHeightWithOverscan() / 2) - 10; font = new BitmapFont(); font.setColor(1.0f, 1.0f, 0.0f, 1.0f); if (!Ouya.runningOnOuya) { font.setScale(1.0f); } else { font.setScale(2.5f); } // Start networking. actionResolver.enableMulticast(); Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads"); serviceDiscoveryThread = ServiceDiscoveryThread.getInstance(); videoThread = VideoStreamingThread.getInstance(); robotThread = RobotControlThread.getInstance(); sensorThread = SensorReportThread.getInstance(); // Launch networking threads. serviceDiscoveryThread.start(); videoThread.start(); videoThread.startStreaming(); videoThread.addNetworkConnectionListener(this); robotThread.addNetworkConnectionListener(this); robotThread.start(); sensorThread.addNetworkConnectionListener(this); sensorThread.start(); // Set the current and next states. currState = game_states_t.MAIN_MENU; nextState = null; this.setScreen(states[currState.getValue()]); states[currState.getValue()].onStateSet(); // Prepare the fading effect. Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444); pixmap.setColor(0, 0, 0, 1); pixmap.fill(); fadeTexture = new Texture(pixmap); pixmap.dispose(); alpha = new MutableFloat(0.0f); fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint); fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint); fading = false; // Set initial input handlers. Gdx.input.setInputProcessor(states[currState.getValue()]); Controllers.addListener(states[currState.getValue()]); // Set log level if (ProjectConstants.DEBUG) { Gdx.app.setLogLevel(Application.LOG_DEBUG); } else { Gdx.app.setLogLevel(Application.LOG_NONE); } }