List of usage examples for com.badlogic.gdx.graphics.g2d PolygonSpriteBatch setBlendFunction
@Override public void setBlendFunction(int srcFunc, int dstFunc)
From source file:com.company.minery.utils.spine.SkeletonRenderer.java
License:Open Source License
@SuppressWarnings("null") public void draw(PolygonSpriteBatch 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; float[] vertices = null; short[] triangles = null; 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 o m*/ Attachment attachment = slot.attachment; Texture texture = null; if (attachment instanceof RegionAttachment) { RegionAttachment region = (RegionAttachment) attachment; region.updateWorldVertices(slot, premultipliedAlpha); vertices = region.getWorldVertices(); triangles = quadTriangles; texture = region.getRegion().getTexture(); } else if (attachment instanceof MeshAttachment) { MeshAttachment mesh = (MeshAttachment) attachment; mesh.updateWorldVertices(slot, premultipliedAlpha); vertices = mesh.getWorldVertices(); triangles = mesh.getTriangles(); texture = mesh.getRegion().getTexture(); } else if (attachment instanceof SkinnedMeshAttachment) { SkinnedMeshAttachment mesh = (SkinnedMeshAttachment) attachment; mesh.updateWorldVertices(slot, premultipliedAlpha); vertices = mesh.getWorldVertices(); triangles = mesh.getTriangles(); texture = mesh.getRegion().getTexture(); } 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.setPosition(0, 0); rootBone.setScaleX(oldScaleX); rootBone.setScaleY(oldScaleY); rootBone.setRotation(oldRotation); } if (texture != null) { 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(texture, vertices, 0, vertices.length, triangles, 0, triangles.length); } } }
From source file:com.esotericsoftware.spine.SkeletonMeshRenderer.java
License:Open Source License
@SuppressWarnings("null") public void draw(PolygonSpriteBatch batch, Skeleton skeleton) { boolean premultipliedAlpha = this.premultipliedAlpha; BlendMode blendMode = null;/*from w w w .jav a 2 s .c om*/ float[] vertices = null; short[] triangles = null; Array<Slot> drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); Attachment attachment = slot.attachment; Texture texture = null; if (attachment instanceof RegionAttachment) { RegionAttachment region = (RegionAttachment) attachment; vertices = region.updateWorldVertices(slot, premultipliedAlpha); triangles = quadTriangles; texture = region.getRegion().getTexture(); } else if (attachment instanceof MeshAttachment) { MeshAttachment mesh = (MeshAttachment) attachment; vertices = mesh.updateWorldVertices(slot, premultipliedAlpha); triangles = mesh.getTriangles(); texture = mesh.getRegion().getTexture(); } 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(bone.getWorldX(), bone.getWorldY()); // rootBone.setScaleX(1 + bone.getWorldScaleX() - oldScaleX); // rootBone.setScaleY(1 + bone.getWorldScaleY() - oldScaleY); // Set shear. rootBone.setRotation(oldRotation + bone.getWorldRotationX()); attachmentSkeleton.updateWorldTransform(); draw(batch, attachmentSkeleton); attachmentSkeleton.setPosition(0, 0); rootBone.setScaleX(oldScaleX); rootBone.setScaleY(oldScaleY); rootBone.setRotation(oldRotation); } if (texture != null) { BlendMode slotBlendMode = slot.data.getBlendMode(); if (slotBlendMode != blendMode) { blendMode = slotBlendMode; batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); } batch.draw(texture, vertices, 0, vertices.length, triangles, 0, triangles.length); } } }
From source file:sg.atom2d.game2d.graphics.anim.spine.skeleton.SkeletonRenderer.java
License:Open Source License
public void draw(PolygonSpriteBatch 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; float[] vertices; short[] triangles; Texture texture;// w w w . ja v a2 s . co m Array<Slot> drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { RegionAttachment region = (RegionAttachment) attachment; region.updateWorldVertices(slot, premultipliedAlpha); vertices = region.getWorldVertices(); triangles = quadTriangle; texture = region.getRegion().getTexture(); 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(texture, vertices, 0, vertices.length, triangles, 0, triangles.length); } else if (attachment instanceof MeshAttachment) { MeshAttachment mesh = (MeshAttachment) attachment; mesh.updateWorldVertices(slot, true); vertices = mesh.getWorldVertices(); triangles = mesh.getTriangles(); texture = mesh.getRegion().getTexture(); batch.draw(texture, vertices, 0, vertices.length, triangles, 0, triangles.length); } 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); } } }
From source file:spine.SkeletonMeshRenderer.java
License:Open Source License
@SuppressWarnings("null") public void draw(PolygonSpriteBatch batch, Skeleton skeleton) { boolean premultipliedAlpha = this.premultipliedAlpha; BlendMode blendMode = null;/*from ww w . j a v a2 s.co m*/ float[] vertices = null; short[] triangles = null; Array<Slot> drawOrder = skeleton.drawOrder; for (int i = 0, n = drawOrder.size; i < n; i++) { Slot slot = drawOrder.get(i); Attachment attachment = slot.attachment; Texture texture = null; if (attachment instanceof RegionAttachment) { RegionAttachment region = (RegionAttachment) attachment; vertices = region.updateWorldVertices(slot, premultipliedAlpha); triangles = quadTriangles; texture = region.getRegion().getTexture(); } else if (attachment instanceof MeshAttachment) { MeshAttachment mesh = (MeshAttachment) attachment; vertices = mesh.updateWorldVertices(slot, premultipliedAlpha); triangles = mesh.getTriangles(); texture = mesh.getRegion().getTexture(); } else if (attachment instanceof SkinnedMeshAttachment) { SkinnedMeshAttachment mesh = (SkinnedMeshAttachment) attachment; vertices = mesh.updateWorldVertices(slot, premultipliedAlpha); triangles = mesh.getTriangles(); texture = mesh.getRegion().getTexture(); } 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.getWorldRotationX()); attachmentSkeleton.updateWorldTransform(); draw(batch, attachmentSkeleton); attachmentSkeleton.setPosition(0, 0); rootBone.setScaleX(oldScaleX); rootBone.setScaleY(oldScaleY); rootBone.setRotation(oldRotation); } if (texture != null) { BlendMode slotBlendMode = slot.data.getBlendMode(); if (slotBlendMode != blendMode) { blendMode = slotBlendMode; batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest()); } batch.draw(texture, vertices, 0, vertices.length, triangles, 0, triangles.length); } } }