private void drawCullingRectangles(ShapeRenderer shapeRenderer, Color color) { for (BoundingBox br : boundingBoxes) { Rectangle r = br.rectangle; Rectangle cullingArea = getCullingArea(tmpRectangle, r, angleRad, position, scale); shapeRenderer.set(ShapeRenderer.ShapeType.Filled); Color fillColor = tmpColor.set(color); fillColor.a *= 0.25f; shapeRenderer.setColor(fillColor); shapeRenderer.rect(cullingArea.x, cullingArea.y, cullingArea.width, cullingArea.height); tmp.set(r.x, r.y).rotateRad(angleRad).add(position); tmp1.set(r.x + r.width, r.y).rotateRad(angleRad).add(position); tmp2.set(r.x + r.width, r.y + r.height).rotateRad(angleRad).add(position); tmp3.set(r.x, r.y + r.height).rotateRad(angleRad).add(position); shapeRenderer.set(ShapeRenderer.ShapeType.Line); shapeRenderer.setColor(color); shapeRenderer.line(tmp, tmp1); shapeRenderer.line(tmp1, tmp2); shapeRenderer.line(tmp2, tmp3); shapeRenderer.line(tmp3, tmp); } }
@Override public void create() { mesh = new Mesh( true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); float c1 = Color.toFloatBits(255, 0, 0, 255); float c2 = Color.toFloatBits(255, 0, 0, 255); ; float c3 = Color.toFloatBits(0, 0, 255, 255); ; mesh.setVertices( new float[] {-0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); spriteBatch = new SpriteBatch(); frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, true); createShader(Gdx.graphics); }
@Override public void create() { vbo = new VertexBufferObject( true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_Position"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_TexCoords"), new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, "a_Color")); float[] vertices = new float[] { -1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f) }; vbo.setVertices(vertices, 0, vertices.length); ibo = new IndexBufferObject(true, 3); ibo.setIndices(new short[] {0, 1, 2}, 0, 3); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); }
private void init( Criteria[] choiceCriteria, Criteria[][] choiceShortCriteria, String[][] choiceShorts, Criteria[][] choiceTextCriteria, String[][] choiceTexts, Criteria[][] proceedKeyCriteria, String[][] proceedKeys) { this.choiceCriteria = choiceCriteria; this.choiceShortCriteria = choiceShortCriteria; this.choiceShorts = choiceShorts; this.choiceTextCriteria = choiceTextCriteria; this.choiceTexts = choiceTexts; this.proceedKeyCriteria = proceedKeyCriteria; this.proceedKeys = proceedKeys; hasBeenSaid = false; madeChoice = false; choice = 0; font = new BitmapFont(Gdx.files.internal("main_text.fnt")); Color temp = character.speechColor; temp.a = 0.7f; font.setColor(temp); font.getData().setScale(1f); }
private void drawFeatheredFullLine( Vector2 a, Vector2 b, float width, float feather, Color color) { checkMaxVerts(3 * 6); // Calculate the normal that defines the center rectangle norm.set(b); norm.sub(a); norm.rotate(90); norm.setLength(width / 2); // Scale to line width // Calculate the normal that defines feathering feath.set(norm); feath.setLength(feather / 2); zeroAlpha.set(color); zeroAlpha.a = 0; // ORDER OF RENDERING // 1 2 // top feather // 3 4 // center // 5 6 // bottom feather // 7 8 // Top feather tL.set(a).add(norm).add(feath); tR.set(b).add(norm).add(feath); bL.set(a).add(norm); bR.set(b).add(norm); // Draw it // Top feather (1-2-3) uncheckedTriangle(tL.x, tL.y, tR.x, tR.y, bL.x, bL.y, zeroAlpha, zeroAlpha, color); uncheckedTriangle(tR.x, tR.y, bL.x, bL.y, bR.x, bR.y, zeroAlpha, color, color); // Center line tL.set(a).add(norm); tR.set(b).add(norm); bL.set(a).sub(norm); bR.set(b).sub(norm); // Draw it uncheckedTriangle(tL.x, tL.y, tR.x, tR.y, bL.x, bL.y, color, color, color); uncheckedTriangle(tR.x, tR.y, bL.x, bL.y, bR.x, bR.y, color, color, color); // Bottom feather tL.set(a).sub(norm); tR.set(b).sub(norm); bL.set(a).sub(norm).sub(feath); bR.set(b).sub(norm).sub(feath); // Draw it uncheckedTriangle(tL.x, tL.y, tR.x, tR.y, bL.x, bL.y, color, color, zeroAlpha); uncheckedTriangle(tR.x, tR.y, bL.x, bL.y, bR.x, bR.y, color, zeroAlpha, zeroAlpha); }
@Override public void blend(Color source, Color dest, Color output) { output.r = (dest.r == 1) ? 1 : source.r / (1 - dest.r); output.g = (dest.g == 1) ? 1 : source.g / (1 - dest.g); output.b = (dest.b == 1) ? 1 : source.b / (1 - dest.b); output.a = dest.a; output.clamp(); }
@Override public void blend(Color source, Color dest, Color output) { output.r = (1 - ((1 - dest.r) * (1 - source.r))); output.g = (1 - ((1 - dest.g) * (1 - source.g))); output.b = (1 - ((1 - dest.b) * (1 - source.b))); output.a = dest.a; output.clamp(); }
@Override public void blend(Color source, Color dest, Color output) { output.r = min(source.r, dest.r); output.g = min(source.g, dest.g); output.b = min(source.b, dest.b); output.a = dest.a; output.clamp(); }
// TCOD_BKGND_OVERLAY @Override public void blend(Color source, Color dest, Color output) { output.r = source.r <= 0.5 ? 2 * (source.r) * dest.r : 1 - 2 * (1 - source.r) * (1 - dest.r); output.g = source.g <= 0.5 ? 2 * (source.g) * dest.g : 1 - 2 * (1 - source.g) * (1 - dest.g); output.b = source.b <= 0.5 ? 2 * (source.b) * dest.b : 1 - 2 * (1 - source.b) * (1 - dest.b); output.a = dest.a; output.clamp(); }
// JCOD Extension @Override public void blend(Color source, Color dest, Color output) { output.r = source.r * source.a + dest.r * (1 - source.a); output.g = source.g * source.a + dest.g * (1 - source.a); output.b = source.b * source.a + dest.b * (1 - source.a); output.a = dest.a; output.clamp(); }
@Override public void blend(Color source, Color dest, Color output) { output.r = (source.r == 0) ? 0 : 1 - (1 - dest.r) / source.r; output.g = (source.g == 0) ? 0 : 1 - (1 - dest.g) / source.g; output.b = (source.b == 0) ? 0 : 1 - (1 - dest.b) / source.b; output.a = dest.a; output.clamp(); }
private void generateBackground(float delta) { // float x = Time.getTime() * backgroundColorSpeed; backgroundColor.r = MathUtils.sin(Time.getTime() * backgroundColorSpeed * 0.8f) * 0.1f + 0.7f; backgroundColor.g = MathUtils.sin(Time.getTime() * backgroundColorSpeed * 0.7f) * 0.1f + 0.7f; backgroundColor.b = MathUtils.sin(Time.getTime() * backgroundColorSpeed * 0.9f) * 0.1f + 0.56f; Gdx.app.log("LOG", String.valueOf(backgroundColor.r)); }
@Override public void create() { String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoords;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n" + "{ \n" + " v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n" + " v_texCoords = a_texCoords; \n" + " gl_Position = a_position; \n" + "} \n"; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}"; shader = new ShaderProgram(vertexShader, fragmentShader); vbo = new VertexBufferObject( true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_position"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_texCoords"), new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, "a_color")); float[] vertices = new float[] { -1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f) }; vbo.setVertices(vertices, 0, vertices.length); indices = new IndexBufferObject(3); indices.setIndices(new short[] {0, 1, 2}, 0, 3); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); }
/** * Returns the color of this font. Changing the returned color will have no affect, {@link * #setColor(Color)} or {@link #setColor(float, float, float, float)} must be used. */ public Color getColor() { int intBits = Float.floatToRawIntBits(color); Color color = this.tempColor; color.r = (intBits & 0xff) / 255f; color.g = ((intBits >>> 8) & 0xff) / 255f; color.b = ((intBits >>> 16) & 0xff) / 255f; color.a = ((intBits >>> 24) & 0xff) / 255f; return color; }
/** * Sets light color * * <p>NOTE: you can also use colorless light with shadows, e.g. (0,0,0,1) * * @param newColor RGB set the color and Alpha set intensity * @see #setColor(float, float, float, float) */ public void setColor(Color newColor) { if (newColor != null) { color.set(newColor); } else { color.set(DefaultColor); } colorF = color.toFloatBits(); if (staticLight) dirty = true; }
/** * @return the rendering color of this SpriteBatch. Manipulating the returned instance has no * effect. */ public Color getColor() { int intBits = NumberUtils.floatToIntColor(color); Color color = this.tempColor; color.r = (intBits & 0xff) / 255f; color.g = ((intBits >>> 8) & 0xff) / 255f; color.b = ((intBits >>> 16) & 0xff) / 255f; color.a = ((intBits >>> 24) & 0xff) / 255f; return color; }
@Override public void blend(Color source, Color dest, Color output) { // can't use set/add/sub methods, they clamp too soon output.r = source.r + dest.r - 1; output.g = source.g + dest.g - 1; output.b = source.b + dest.b - 1; output.a = dest.a; output.clamp(); }
public void setColor(ObjectType type) { switch (type) { case RED: color = Color.valueOf(MainGame.COLOR_RED); break; case GREEN: color = Color.valueOf(MainGame.COLOR_GREEN); break; } }
public static Color stringToColor(String string) { Color c = new Color(); if (string.length() < 8) throw new IllegalArgumentException(); // int rgba = Integer.valueOf(string.substring(0, 8), 16); int r = Integer.valueOf(string.substring(0, 2), 16); int g = Integer.valueOf(string.substring(2, 4), 16); int b = Integer.valueOf(string.substring(4, 6), 16); int a = Integer.valueOf(string.substring(6, 8), 16); c.set(r / 255f, g / 255f, b / 255f, a / 255f); // c.set(rgba); return c; }
public void drawMenuBoxSelected(Vector2 position, float menuWidth, float menuHeight) { // TODO probably a better way to do this Color orgColor = new Color(com.nerddaygames.rupert.games.Protect.managers.AssetsManager.menuBox.getColor()); Color color = new Color(com.nerddaygames.rupert.games.Protect.managers.AssetsManager.menuBox.getColor()); color.a = color.a / 2; batch.setColor(color); com.nerddaygames.rupert.games.Protect.managers.AssetsManager.menuBox.draw( batch, position.x, position.y, menuWidth, menuHeight); batch.setColor(orgColor); }
private float getColor(ColourDiffuse colourDiffuse) { String[] tokens = colourDiffuse.getValue().split(" "); if (tokens.length == 3) color.set(Float.valueOf(tokens[0]), Float.valueOf(tokens[1]), Float.valueOf(tokens[2]), 1); else color.set( Float.valueOf(tokens[0]), Float.valueOf(tokens[1]), Float.valueOf(tokens[2]), Float.valueOf(tokens[3])); return color.toFloatBits(); }
public void drawTriangle( int x, int y, float w, float h, double rotation, double speed, double color, double puls) { if (once == 0) { System.out.println("Triangle entered"); // Image this.rectX = x; this.rectY = y; this.width = w; this.height = h; // Rotation purposes originX = x; originY = y; // Mesh Purposes float colour = Color.toFloatBits(0, 0, 0, 255); // default is black if (color == 1) { colour = Color.toFloatBits(255, 255, 255, 255); // set to white } float z = 0; float[] vertices = {x, y, z, colour, x, y, z, colour, x, y, z, colour}; float[] verticesTri = { x, y, x, y, x, y, }; this.verticesMesh = vertices; this.verticesPoly = verticesTri; this.speed = speed; this.rotation = rotation; this.color = color; this.pulsating = puls; once++; } // Triangle Polygon poly(); // Image rectX -= this.speed; rectY -= this.speed; width += this.speed * 2; height += this.speed * 2; // Update Indices once after poly() if (once < 10) { indices = Helper.earclip.computeTriangles(verticesPoly).toArray(); once++; } }
public static void showTips(String text, float originX, float originY, Color color) { // Vector3 pos = new Vector3(originX, originY, 0.0f); // CameraController.getInstance(CameraController.class).worldToScreen(pos); TipsBillborad tip = allocTipsBillboard(); tip.life = 0.0f; tip.text = text; tip.oringinX = originX; tip.oringinY = originY; tip.velocity.x = 0.0f; tip.velocity.y = Settings.UNIT * 0.2f; tip.color.r = color.r; tip.color.g = color.g; tip.color.b = color.b; }
@Override public Tint tween(Tint a, Tint b, float value) { final Interpolation linear = Interpolation.linear; final Color colorA = a.color; final Color colorB = b.color; color.r = linear.apply(colorA.r, colorB.r, value); color.g = linear.apply(colorA.g, colorB.g, value); color.b = linear.apply(colorA.b, colorB.b, value); color.a = linear.apply(colorA.a, colorB.a, value); return this; }
public void drawCircle(Vector2 center, float rad, float feath, int segs, Color col) { if (segs < 3) { throw new IllegalArgumentException("Segs must be > 3"); } if (rad == 0) { return; } drawCircle(center, rad, segs, col); tmpCol1.set(col); tmpCol1.a = 0; drawArc(center, rad, rad + feath, segs, col, tmpCol1); }
@Override public final void _render(SpriteBatch spriteBatch) { if (frozen) { // set shader float brightness = .5f / (freezeCounterMax / freezeCounter); spriteBatch.setShader(Shader.FREEZE_SHADER); spriteBatch.getShader().setUniformf("u_contrast", 1.1f); spriteBatch.getShader().setUniformf("u_brightness", brightness); // set color frozenColor.a = FROZEN_COLOR_START_ALPHA / (freezeCounterMax / freezeCounter); spriteBatch.setColor(frozenColor); // render doRender(spriteBatch); // reset shader spriteBatch.setShader(null); // reset color spriteBatch.setColor(Color.WHITE); } else { doRender(spriteBatch); } }
@Override public void draw(Batch batch, float parentAlpha) { LibGDXTextureUtilities.checkLibGDXTexture((Reactor) getBinded()); // calculate coordinates int index = GameRegistry.instance().getInventory().getItems().indexOf(this.coreObject); if (index == -1) { // bad guy remove(); return; } int x = 2 + (48 * (index % 2)); int y = 6 + (60 * (index / 2)); // set them, with the appropriate offsets // TODO - this is extremely ugly, refactor it // TODO: Do not refactor. This is not my refactoring this.setX(700 + x); this.setY(480 - y - 48); // add "halo" if the item is selected if (((Item) coreObject).getIsSelected()) { batch.setColor(Color.rgba8888(0, 0.5f, 0.5f, 0.4f)); } else { batch.setColor(Color.WHITE); } // TODO: Ugly large batch.draw( ((LibGDXTextureWrapper) ((Reactor) getBinded()).getImage()).getGdxTexture(), this.getX(), this.getY(), 48, 48); }
/** Builds final vertices with vertex attributes like coordinates, color and region u/v */ private void buildVertices() { vertices.clear(); for (int i = 0; i < parts.size; i++) { float verts[] = parts.get(i); if (verts == null) continue; float[] fullVerts = new float[5 * verts.length / 2]; int idx = 0; int col = i / rows; int row = i % rows; for (int j = 0; j < verts.length; j += 2) { fullVerts[idx++] = verts[j] + offset.x + x; fullVerts[idx++] = verts[j + 1] + offset.y + y; fullVerts[idx++] = color.toFloatBits(); float u = (verts[j] % gridWidth) / gridWidth; float v = (verts[j + 1] % gridHeight) / gridHeight; if (verts[j] == col * gridWidth) u = 0f; if (verts[j] == (col + 1) * gridWidth) u = 1f; if (verts[j + 1] == row * gridHeight) v = 0f; if (verts[j + 1] == (row + 1) * gridHeight) v = 1f; u = region.getU() + (region.getU2() - region.getU()) * u; v = region.getV() + (region.getV2() - region.getV()) * v; fullVerts[idx++] = u; fullVerts[idx++] = v; } vertices.add(fullVerts); } dirty = false; }
@Override public void render() { red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1; Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); logoSprite.draw(spriteBatch); switch (renderMode) { case 0: font.getData().setScale(1); renderNormal("normal"); break; case 1: font.getData().setScale(1); renderCached(); break; case 2: font.getData().setScale(red.a + 0.5f); renderNormal("normal scaled"); break; case 3: font.getData().setScale(1); renderCachedScaled(); break; } spriteBatch.end(); }
@Override public short vertex(Vector3 pos, Vector3 nor, Color col, Vector2 uv) { if (vindex >= Short.MAX_VALUE) throw new GdxRuntimeException("Too many vertices used"); if (col == null && colorSet) col = color; if (pos != null) { vertex[posOffset] = pos.x; if (posSize > 1) vertex[posOffset + 1] = pos.y; if (posSize > 2) vertex[posOffset + 2] = pos.z; } if (nor != null && norOffset >= 0) { vertex[norOffset] = nor.x; vertex[norOffset + 1] = nor.y; vertex[norOffset + 2] = nor.z; } if (col != null) { if (colOffset >= 0) { vertex[colOffset] = col.r; vertex[colOffset + 1] = col.g; vertex[colOffset + 2] = col.b; if (colSize > 3) vertex[colOffset + 3] = col.a; } else if (cpOffset > 0) vertex[cpOffset] = col.toFloatBits(); // FIXME cache packed color? } if (uv != null && uvOffset >= 0) { vertex[uvOffset] = uv.x; vertex[uvOffset + 1] = uv.y; } vertices.addAll(vertex); return (short) (vindex++); }