List of usage examples for com.badlogic.gdx.graphics.g2d Batch setBlendFunction
public void setBlendFunction(int srcFunc, int dstFunc);
From source file:com.company.minery.utils.spine.SkeletonRenderer.java
License:Open Source License
public void draw(Batch batch, Skeleton skeleton) { boolean premultipliedAlpha = this.premultipliedAlpha; int srcFunc = premultipliedAlpha ? GL20.GL_ONE : GL20.GL_SRC_ALPHA; batch.setBlendFunction(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA); boolean additive = false; Array<Slot> drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i);//from w w w. j a v a 2 s. co m Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment) attachment; regionAttachment.updateWorldVertices(slot, premultipliedAlpha); float[] vertices = regionAttachment.getWorldVertices(); if (slot.data.getAdditiveBlending() != additive) { additive = !additive; if (additive) batch.setBlendFunction(srcFunc, GL20.GL_ONE); else batch.setBlendFunction(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA); } batch.draw(regionAttachment.getRegion().getTexture(), vertices, 0, 20); } else if (attachment instanceof MeshAttachment || attachment instanceof SkinnedMeshAttachment) { throw new RuntimeException("PolygonSpriteBatch is required to render meshes."); } else if (attachment instanceof SkeletonAttachment) { Skeleton attachmentSkeleton = ((SkeletonAttachment) attachment).getSkeleton(); if (attachmentSkeleton == null) continue; Bone bone = slot.getBone(); Bone rootBone = attachmentSkeleton.getRootBone(); float oldScaleX = rootBone.getScaleX(); float oldScaleY = rootBone.getScaleY(); float oldRotation = rootBone.getRotation(); attachmentSkeleton.setPosition(skeleton.getX() + bone.getWorldX(), skeleton.getY() + bone.getWorldY()); rootBone.setScaleX(1 + bone.getWorldScaleX() - oldScaleX); rootBone.setScaleY(1 + bone.getWorldScaleY() - oldScaleY); rootBone.setRotation(oldRotation + bone.getWorldRotation()); attachmentSkeleton.updateWorldTransform(); draw(batch, attachmentSkeleton); attachmentSkeleton.setX(0); attachmentSkeleton.setY(0); rootBone.setScaleX(oldScaleX); rootBone.setScaleY(oldScaleY); rootBone.setRotation(oldRotation); } } }
From source file:com.github.fauu.helix.graphics.ParticleEmitter.java
License:Apache License
public void draw(Batch batch) { if (premultipliedAlpha) { batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA); } else if (additive) { batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); } else {/*from w w w . j av a 2 s. c o m*/ batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } Particle[] particles = this.particles; boolean[] active = this.active; for (int i = 0, n = active.length; i < n; i++) { if (active[i]) particles[i].draw(batch); } if (cleansUpBlendFunction && (additive || premultipliedAlpha)) batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); }
From source file:com.github.fauu.helix.graphics.ParticleEmitter.java
License:Apache License
/** Updates and draws the particles. This is slightly more efficient than calling {@link #update(float, float, float)} and * {@link #draw(batch)} separately. */ public void draw(Batch batch, float delta) { accumulator += delta * 1000;/*from w w w .j a v a 2s .c o m*/ if (accumulator < 1) { draw(batch); return; } int deltaMillis = (int) accumulator; accumulator -= deltaMillis; if (premultipliedAlpha) { batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA); } else if (additive) { batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); } else { batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } Particle[] particles = this.particles; boolean[] active = this.active; int activeCount = this.activeCount; for (int i = 0, n = active.length; i < n; i++) { if (active[i]) { Particle particle = particles[i]; if (updateParticle(particle, 0, 0, delta, deltaMillis)) particle.draw(batch); else { active[i] = false; activeCount--; } } } this.activeCount = activeCount; if (cleansUpBlendFunction && (additive || premultipliedAlpha)) batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); if (delayTimer < delay) { delayTimer += deltaMillis; return; } if (firstUpdate) { firstUpdate = false; addParticle(); } if (durationTimer < duration) durationTimer += deltaMillis; else { if (!continuous || allowCompletion) return; restart(); } emissionDelta += deltaMillis; float emissionTime = emission + emissionDiff * emissionValue.getScale(durationTimer / (float) duration); if (emissionTime > 0) { emissionTime = 1000 / emissionTime; if (emissionDelta >= emissionTime) { int emitCount = (int) (emissionDelta / emissionTime); emitCount = Math.min(emitCount, maxParticleCount - activeCount); emissionDelta -= emitCount * emissionTime; emissionDelta %= emissionTime; addParticles(emitCount); } } if (activeCount < minParticleCount) addParticles(minParticleCount - activeCount); }
From source file:io.piotrjastrzebski.playground.particletest.MyEmitter.java
License:Apache License
/** Updates and draws the particles. This is slightly more efficient than calling {@link #update(float)} and * {@link #draw(Batch)} separately. */ public void draw(Batch batch, float delta) { accumulator += delta * 1000;/* w w w. j ava 2 s .c om*/ if (accumulator < 1) { draw(batch); return; } int deltaMillis = (int) accumulator; accumulator -= deltaMillis; if (premultipliedAlpha) { batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA); } else if (additive) { batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); } else { batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } Particle[] particles = this.particles; boolean[] active = this.active; int activeCount = this.activeCount; for (int i = 0, n = active.length; i < n; i++) { if (active[i]) { Particle particle = particles[i]; if (updateParticle(particle, delta, deltaMillis)) particle.draw(batch); else { active[i] = false; activeCount--; } } } this.activeCount = activeCount; if (cleansUpBlendFunction && (additive || premultipliedAlpha)) batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); if (delayTimer < delay) { delayTimer += deltaMillis; return; } if (firstUpdate) { firstUpdate = false; addParticle(); } if (durationTimer < duration) durationTimer += deltaMillis; else { if (!continuous || allowCompletion) return; restart(); } emissionDelta += deltaMillis; float emissionTime = emission + emissionDiff * emissionValue.getScale(durationTimer / (float) duration); if (emissionTime > 0) { emissionTime = 1000 / emissionTime; if (emissionDelta >= emissionTime) { int emitCount = (int) (emissionDelta / emissionTime); emitCount = Math.min(emitCount, maxParticleCount - activeCount); emissionDelta -= emitCount * emissionTime; emissionDelta %= emissionTime; addParticles(emitCount); } } if (activeCount < minParticleCount) addParticles(minParticleCount - activeCount); }
From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java
License:Apache License
protected void drawParticles(Batch batch) { int srcFunc = batch.getBlendSrcFunc(); int dstFunc = batch.getBlendDstFunc(); batch.setBlendFunction(blendSrc, blendDst); //System.out.println("_particleCount:"+_particleCount); for (int i = 0; i < _particleCount; i++) { batch.draw(m_pTexture, vertices[i], 0, 20); }//from w w w .j ava 2s . c o m batch.setBlendFunction(srcFunc, dstFunc); // batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); }
From source file:patch.libgdx.ParticleEmitter.java
License:Apache License
public void draw(Batch batch) { if (premultipliedAlpha) { batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA); } else if (additive) { batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); } else {/* w ww . j a va 2s . c om*/ batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } Particle[] particles = this.particles; boolean[] active = this.active; if (culling) { for (int i = 0, n = active.length; i < n; i++) { if (!active[i]) { continue; } final Particle particle = particles[i]; final float x = particle.getX(); if (x + particle.getWidth() < cullMin || x > cullMax) { continue; } particle.draw(batch); } } else { for (int i = 0, n = active.length; i < n; i++) { if (active[i]) particles[i].draw(batch); } } if (cleansUpBlendFunction && (additive || premultipliedAlpha)) batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); }
From source file:sg.atom2d.game2d.graphics.anim.spine.skeleton.SkeletonRenderer.java
License:Open Source License
public void draw(Batch batch, Skeleton skeleton) { boolean premultipliedAlpha = this.premultipliedAlpha; int srcFunc = premultipliedAlpha ? GL11.GL_ONE : GL11.GL_SRC_ALPHA; batch.setBlendFunction(srcFunc, GL11.GL_ONE_MINUS_SRC_ALPHA); boolean additive = false; Array<Slot> drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i);/*from w w w . ja v a 2 s .c om*/ Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment) attachment; regionAttachment.updateWorldVertices(slot, premultipliedAlpha); float[] vertices = regionAttachment.getWorldVertices(); if (slot.data.getAdditiveBlending() != additive) { additive = !additive; if (additive) { batch.setBlendFunction(srcFunc, GL11.GL_ONE); } else { batch.setBlendFunction(srcFunc, GL11.GL_ONE_MINUS_SRC_ALPHA); } } batch.draw(regionAttachment.getRegion().getTexture(), vertices, 0, 20); } else if (attachment instanceof SkeletonAttachment) { Skeleton attachmentSkeleton = ((SkeletonAttachment) attachment).getSkeleton(); if (attachmentSkeleton == null) { continue; } Bone bone = slot.getBone(); Bone rootBone = attachmentSkeleton.getRootBone(); float oldScaleX = rootBone.getScaleX(); float oldScaleY = rootBone.getScaleY(); float oldRotation = rootBone.getRotation(); attachmentSkeleton.setX(bone.getWorldX()); attachmentSkeleton.setY(bone.getWorldY()); rootBone.setScaleX(1 + bone.getWorldScaleX() - oldScaleX); rootBone.setScaleY(1 + bone.getWorldScaleY() - oldScaleY); rootBone.setRotation(oldRotation + bone.getWorldRotation()); attachmentSkeleton.updateWorldTransform(); draw(batch, attachmentSkeleton); attachmentSkeleton.setX(0); attachmentSkeleton.setY(0); rootBone.setScaleX(oldScaleX); rootBone.setScaleY(oldScaleY); rootBone.setRotation(oldRotation); } } }