List of usage examples for com.badlogic.gdx.graphics GL20 GL_ONE
int GL_ONE
To view the source code for com.badlogic.gdx.graphics GL20 GL_ONE.
Click Source Link
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;/*from ww w. ja va 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.bplaced.therefactory.nomoore.utils.Particles.java
License:Open Source License
private void resetBlendFunction(SpriteBatch batch) { batch.setBlendFunction(-1, -1);//from w ww .j a v a2s. c om Gdx.gl20.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_DST_ALPHA); }
From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java
License:Apache License
public void initWithTotalParticles(int numberOfParticles, Texture texture) { _totalParticles = numberOfParticles; m_pParticles = new Particle[_totalParticles]; vertices = new float[_totalParticles][20]; m_uAllocatedParticles = numberOfParticles; _isActive = true;//from w ww . j ava 2s. c o m // default blend function blendSrc = GL20.GL_ONE; blendDst = GL20.GL_ONE_MINUS_SRC_ALPHA; _positionType = PositionTypeFree; _emitterMode = ParticleModeGravity; // _isAutoRemoveOnFinish = false; if (texture != null) { ownesTexture = false; setTexture(m_pTexture); } else { ownesTexture = true; } }
From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java
License:Apache License
public void setBlendAdditive(boolean additive) { if (additive) { blendSrc = GL20.GL_SRC_ALPHA;/*from w w w. j a va 2 s . co m*/ blendDst = GL20.GL_ONE; } else { if (!preMultipliedAlpha) { blendSrc = GL20.GL_SRC_ALPHA; blendDst = GL20.GL_ONE_MINUS_SRC_ALPHA; } else { blendSrc = GL20.GL_ONE; blendDst = GL20.GL_ONE_MINUS_SRC_ALPHA; } } }
From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java
License:Apache License
protected void updateBlendFunc() { m_bOpacityModifyRGB = false;/*from w w w . ja v a2 s . co m*/ if (blendSrc == GL20.GL_ONE && blendDst == GL20.GL_ONE_MINUS_SRC_ALPHA) { if (preMultipliedAlpha) { m_bOpacityModifyRGB = true; } else { blendSrc = GL20.GL_SRC_ALPHA; blendDst = 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 {//from ww w . 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:seventh.client.gfx.effects.particle_system.BlendingSpriteParticleRenderer.java
License:Open Source License
@Override public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) { int src = canvas.getSrcBlendFunction(); int dst = canvas.getDstBlendFunction(); //canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_FUNC_ADD); canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); Gdx.gl20.glBlendEquation(GL20.GL_FUNC_ADD); Vector2f cameraPos = camera.getRenderPosition(alpha); for (int i = 0; i < particles.numberOfAliveParticles; i++) { Sprite sprite = particles.sprite[i]; Vector2f pos = particles.pos[i]; sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y); sprite.setScale(particles.scale[i]); sprite.setColor(particles.color[i]); sprite.setRotation(particles.rotation[i]); canvas.drawRawSprite(sprite);/*from w ww. ja va2s. c o m*/ } canvas.setBlendFunction(src, dst); }
From source file:seventh.client.gfx.effects.particle_system.FireParticleRenderer.java
License:Open Source License
@Override public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) { int src = canvas.getSrcBlendFunction(); int dst = canvas.getDstBlendFunction(); //canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_FUNC_ADD); canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); Gdx.gl20.glBlendEquation(GL20.GL_FUNC_ADD); Vector2f cameraPos = camera.getRenderPosition(alpha); for (int i = 0; i < particles.numberOfAliveParticles; i++) { Sprite sprite = particles.sprite[i]; Vector2f pos = particles.pos[i]; sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y); sprite.setScale(particles.scale[i]); sprite.setColor(particles.color[i]); canvas.drawRawSprite(sprite);//from w w w .j a v a 2s . c om } canvas.setBlendFunction(src, dst); }
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);//w w w . j a va2s . 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(); }