List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch getProjectionMatrix
@Override
public Matrix4 getProjectionMatrix()
From source file:com.badlogic.gdx.tests.PremultiplyAlpha.java
private void gpuPremultiplyAlpha(String in, String out) { Texture texture = new Texture(Gdx.files.absolute(in)); texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest); FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, texture.getWidth(), texture.getHeight(), false); buffer.getColorBufferTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); ShaderProgram shader = new ShaderProgram(VERTEX_SHADER, FRAG_SHADER); Gdx.app.log("Log", shader.getLog()); SpriteBatch batch = new SpriteBatch(10); batch.getProjectionMatrix().setToOrtho2D(0, 0, texture.getWidth(), texture.getHeight()); batch.disableBlending();/* ww w. j av a 2s. c o m*/ batch.setShader(shader); //Premultiply buffer.begin(); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 0, 0); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight()); buffer.end(); //Save PixmapIO.writePNG(Gdx.files.absolute(out), pixmap); buffer.dispose(); texture.dispose(); pixmap.dispose(); Gdx.app.exit(); }
From source file:com.bladecoder.engine.model.Sprite3DRenderer.java
License:Apache License
@Override public void draw(SpriteBatch batch, float x, float y, float scale) { x = x - getWidth() / 2 * scale;/*from w w w. ja v a2 s.co m*/ if (USE_FBO) { batch.draw(tex, x, y, 0, 0, width, height, scale, scale, 0); } else { float p0x, p0y, pfx, pfy; Vector3 tmp = new Vector3(); // TODO Make static for performance? updateViewport(); // get screen coords for x and y tmp.set(x, y, 0); tmp.mul(batch.getTransformMatrix()); tmp.prj(batch.getProjectionMatrix()); p0x = VIEWPORT.width * (tmp.x + 1) / 2; p0y = VIEWPORT.height * (tmp.y + 1) / 2; tmp.set(x + width * scale, y + height * scale, 0); tmp.mul(batch.getTransformMatrix()); tmp.prj(batch.getProjectionMatrix()); pfx = VIEWPORT.width * (tmp.x + 1) / 2; pfy = VIEWPORT.height * (tmp.y + 1) / 2; batch.end(); Gdx.gl20.glViewport((int) (p0x + VIEWPORT.x), (int) (p0y + VIEWPORT.y), (int) (pfx - p0x), (int) (pfy - p0y)); Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0)); drawModel(); Gdx.gl20.glViewport((int) VIEWPORT.x, (int) VIEWPORT.y, (int) VIEWPORT.width, (int) VIEWPORT.height); batch.begin(); } }
From source file:com.disc.jammers.states.StatePlay.java
@Override public void render(SpriteBatch sb) { sb.setProjectionMatrix(camera.combined); debugMatrix = sb.getProjectionMatrix().cpy().scale(PIXEL_PER_METER, PIXEL_PER_METER, 0); b2dr.render(world, debugMatrix);//from w w w .j a v a 2 s . co m manager.render(sb); }
From source file:com.github.unluckyninja.defenseofhuman.model.GameWorld.java
License:Open Source License
public void drawDebug(SpriteBatch batch) { debugRenderer.render(world, batch.getProjectionMatrix()); }
From source file:com.gsn.engine.template.GsnLabel.java
License:Apache License
@Override public void draw(SpriteBatch batch, float parentAlpha) { validate();// w w w. ja va 2s . c o m camera.combined.set(batch.getProjectionMatrix()).mul(batch.getTransformMatrix()); vector.set(x, y, 0); camera.project(vector); batch.end(); sprite.begin(); cache.setPosition(vector.x, vector.y); cache.draw(sprite, color.a * parentAlpha); sprite.end(); batch.begin(); }
From source file:com.minekrash.game.Plataforma.java
public void draw(SpriteBatch g) { if (isAlive) { plataforma.draw(g);//ww w . ja v a2s. co m if (DEBUG) { debug.setProjectionMatrix(g.getProjectionMatrix()); debug.begin(ShapeRenderer.ShapeType.Line); debug.setColor(Color.GREEN); debug.rect(plataforma.getX(), plataforma.getY(), plataforma.getWidth(), plataforma.getHeight()); debug.end(); } } }
From source file:com.minekrash.game.Vagon.java
public void draw(SpriteBatch g) { vagonSprite.draw(g);/*from www. j a v a 2 s .c o m*/ //Humo for (int i = 0; i < humo.length; i++) { humo[i].draw(g); } if (DEBUG) { debug.setProjectionMatrix(g.getProjectionMatrix()); debug.begin(ShapeRenderer.ShapeType.Line); debug.setColor(Color.GREEN); debug.rect(vagonSprite.getX(), vagonSprite.getY(), vagonSprite.getWidth(), vagonSprite.getHeight()); debug.end(); } }
From source file:com.ridiculousRPG.map.tiled.TiledMapWithEvents.java
License:Apache License
public void draw(SpriteBatch spriteBatch, Camera camera, boolean debug) { List<EventObject> dynamicRegions = this.dynamicRegions; Collections.sort(dynamicRegions); // Load pointers into register MapRenderRegion[] staticRegions = this.staticRegions; MapRenderRegion region;// w w w.j a v a2 s . c om Rectangle2D.Float drawBound; // Load variables into register float camX1 = camera.position.x; float camX2 = camera.position.x + camera.viewportWidth; float camY1 = camera.position.y; float camY2 = camera.position.y + camera.viewportHeight; int i = 0; EventObject event = dynamicRegions.get(0); // is never empty int dynSize = dynamicRegions.size(); // If there are performance problems: // USE SPRITECACHE TO RENDER STATIC TILES!!!!! // 1) Add only MapRenderRegions with z>0 to staticRegions // 2) Build a new 3-dim array with [row][col][layer] for all // MapRenderRegions with z==0 // 3) compute firstRow, lastRow, firstCol, lastCol // 4) iterate over // [firstRow<row<lastRow][firstCol<col<lastCol][allLayers] // com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer is not usable // (Tested and felt really bad) for (int j = 0, statSize = staticRegions.length; j < statSize; j++) { region = staticRegions[j]; float rX = region.x; float rY = region.y; if (rX < camX2 && rY < camY2 && rX + region.width > camX1 && rY + region.height > camY1) { while (dynSize > i && event.compareTo(region) == -1) { if (event.visible) { drawBound = event.drawBound; if (drawBound.x < camX2 && drawBound.y < camY2 && drawBound.x + drawBound.width > camX1 && drawBound.y + drawBound.height > camY1) event.draw(spriteBatch); } i++; if (dynSize > i) event = dynamicRegions.get(i); } region.draw(spriteBatch); } } while (dynSize > i) { event = dynamicRegions.get(i); if (event.visible) { drawBound = event.drawBound; if (drawBound.x < camX2 && drawBound.y < camY2 && drawBound.x + drawBound.width > camX1 && drawBound.y + drawBound.height > camY1) event.draw(spriteBatch); } i++; } // draw polygon objects spriteBatch.end(); PolygonObject.startPolygonBatch(spriteBatch.getProjectionMatrix()); for (int j = 0, len = polyList.size(); j < len; j++) polyList.get(j).draw(debug); PolygonObject.endPolygonBatch(); if (debug) { DebugHelper.debugEvents(dynamicRegions); DebugHelper.debugPolygons(polyList); } spriteBatch.begin(); }
From source file:de.r2soft.empires.client.maps.sun.SolarGroup.java
License:Open Source License
public void draw(SpriteBatch batch, float parentAlpha) { batch.end();//from w w w. j a v a 2 s . co m shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix()); shapeRenderer.setTransformMatrix(batch.getTransformMatrix()); shapeRenderer.translate(getX() / 2, getY() / 2, 0); // shapeRenderer.begin(ShapeType.Circle); shapeRenderer.circle((Gdx.graphics.getWidth() / 2) + offsetX, Gdx.graphics.getHeight() / 2, (float) system.getRadius()); shapeRenderer.circle((Gdx.graphics.getWidth() / 2) + offsetX, Gdx.graphics.getHeight() / 2, (float) (system.getRadius() + 25)); shapeRenderer.end(); batch.begin(); applyTransform(batch, computeTransform()); drawChildren(batch, parentAlpha); // switch (system.getStar().getClassification()) { // case BROWNDWARF: // batch.draw(Assets.STARS_BROWN_DWARF, Find.getCenter().x - (Values.SIZE_CELESTIAL_BROWN_DWARF // / 2) + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_BROWN_DWARF / 2), 0, 0, Values.SIZE_CELESTIAL_BROWN_DWARF, // Values.SIZE_CELESTIAL_BROWN_DWARF, 1, 1, 0); // break; // // case BLUEGIANT: // batch.draw(Assets.STARS_BLUE_GIANT, Find.getCenter().x - (Values.SIZE_CELESTIAL_BLUE_GIANT / // 2) + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_BLUE_GIANT / 2), 0, 0, Values.SIZE_CELESTIAL_BLUE_GIANT, // Values.SIZE_CELESTIAL_BLUE_GIANT, 1, 1, 0); // break; // // case NEUTRON: // batch.draw(Assets.STARS_BLUE_DWARF, Find.getCenter().x - (Values.SIZE_CELESTIAL_BLUE_DWARF / // 2) + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_BLUE_DWARF / 2), 0, 0, Values.SIZE_CELESTIAL_BLUE_DWARF, // Values.SIZE_CELESTIAL_BLUE_DWARF, 1, 1, 0); // break; // // case REDDWARF: // batch.draw(Assets.STARS_RED_DWARF, Find.getCenter().x - (Values.SIZE_CELESTIAL_RED_DWARF / 2) // + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_RED_DWARF / 2), 0, 0, Values.SIZE_CELESTIAL_RED_DWARF, // Values.SIZE_CELESTIAL_RED_DWARF, 1, 1, 0); // break; // // case REDGIANT: // batch.draw(Assets.STARS_RED_GIANT, Find.getCenter().x - (Values.SIZE_CELESTIAL_RED_GIANT / 2) // + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_RED_GIANT / 2), 0, 0, Values.SIZE_CELESTIAL_RED_GIANT, // Values.SIZE_CELESTIAL_RED_GIANT, 1, 1, 0); // break; // // default: // break; // } // DRAW END }
From source file:kyle.game.besiege.army.ArmyPlayer.java
License:Open Source License
@Override public void draw(SpriteBatch batch, float parentAlpha) { batch.draw(getTextureRegion(), getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), 1, 1, getRotation());// ww w . ja va 2 s . c o m if (Map.debug) { batch.end(); sr.begin(ShapeType.Line); sr.setProjectionMatrix(batch.getProjectionMatrix()); sr.setColor(1, 0, 0, 1); Destination prev; prev = this; // do in reverse order (Stack!) for (Destination curr : path.dStack) { if (prev != null && curr != null && prev != curr) { sr.line((float) prev.getX(), (float) (prev.getY()), (float) curr.getX(), (float) (curr.getY())); } prev = curr; } sr.end(); batch.begin(); } //if (mousedOver()) drawInfo(batch, parentAlpha); }