Java 类com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer 实例源码

项目:space-travels-3    文件:ShapeRendererUtils.java   
public static void arc(
    ShapeRenderer shapeRenderer,
    float x,
    float y,
    float radius,
    float start,
    float degrees,
    int segments,
    float width)
{
    if (segments <= 0)
    {
        throw new IllegalArgumentException("segments must be > 0.");
    }

    float theta = (2 * MathUtils.PI * (degrees / 360.0f)) / segments;
    float cos = MathUtils.cos(theta);
    float sin = MathUtils.sin(theta);
    float cx = radius * MathUtils.cos(start * MathUtils.degreesToRadians);
    float cy = radius * MathUtils.sin(start * MathUtils.degreesToRadians);
    float halfWidth = width * 0.5f;

    float colorBits = shapeRenderer.getColor().toFloatBits();

    ShapeRenderer.ShapeType oldShapeType = shapeRenderer.getCurrentType();
    shapeRenderer.set(ShapeRenderer.ShapeType.Filled);

    ImmediateModeRenderer renderer = shapeRenderer.getRenderer();

    try (PooledVector2 perpendicular = PooledVector2.newVector2(0f, 0f))
    {
        float x2 = x + cx;
        float y2 = y + cy;
        for (int i = 0; i < segments; i++)
        {
            float x1 = x2;
            float y1 = y2;
            float temp = cx;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            x2 = x + cx;
            y2 = y + cy;

            perpendicular.set(y2 - y1, x1 - x2).nor();
            float tx = perpendicular.x * halfWidth;
            float ty = perpendicular.y * halfWidth;
            renderer.color(colorBits);
            renderer.vertex(x1 + tx, y1 + ty, 0);
            renderer.color(colorBits);
            renderer.vertex(x1 - tx, y1 - ty, 0);
            renderer.color(colorBits);
            renderer.vertex(x2 + tx, y2 + ty, 0);

            renderer.color(colorBits);
            renderer.vertex(x2 - tx, y2 - ty, 0);
            renderer.color(colorBits);
            renderer.vertex(x2 + tx, y2 + ty, 0);
            renderer.color(colorBits);
            renderer.vertex(x1 - tx, y1 - ty, 0);
        }
    }

    shapeRenderer.set(oldShapeType);
}
项目:GdxDemo3D    文件:MyShapeRenderer.java   
public ImmediateModeRenderer getRenderer() {
    return renderer;
}
项目:tutorial-libgdx    文件:ShapeRenderer.java   
public ImmediateModeRenderer getRenderer () {
    return renderer;
}
项目:c2d-engine    文件:WaterTest.java   
public void render(float delta) {
    Gdx.gl.glEnable(GL20.GL_BLEND);
    final ImmediateModeRenderer renderer = Engine.getShapeRenderer().getRenderer();
    Engine.getShapeRenderer().begin(ShapeType.Filled);
    for (int i = 1; i < columns.length; i++) {

        Vector2 p1 = new Vector2((i - 1) * scale, 0);
        Vector2 p2 = new Vector2((i - 1) * scale, columns[i - 1].Height);
        Vector2 p3 = new Vector2(i * scale, columns[i].Height);
        Vector2 p4 = new Vector2(i * scale, 0);

        renderer.color(color1.r, color1.g, color1.b, color1.a);
        renderer.vertex(p1.x, p1.y, 0);
        renderer.color(color2.r, color2.g, color2.b, color2.a);
        renderer.vertex(p2.x, p2.y, 0);
        renderer.color(color2.r, color2.g, color2.b, color2.a);
        renderer.vertex(p3.x, p3.y, 0);

        renderer.color(color2.r, color2.g, color2.b, color2.a);
        renderer.vertex(p3.x, p3.y, 0);
        renderer.color(color1.r, color1.g, color1.b, color1.a);
        renderer.vertex(p4.x, p4.y, 0);
        renderer.color(color1.r, color1.g, color1.b, color1.a);
        renderer.vertex(p1.x, p1.y, 0);


        renderer.color(color1.r, color1.g, color1.b, color1.a * 0.3f);
        renderer.vertex(p1.x, p2.y - tinkness, 0);
        renderer.color(color2.r, color2.g, color2.b, color2.a * 0.3f);
        renderer.vertex(p2.x, p2.y, 0);
        renderer.color(color2.r, color2.g, color2.b, color2.a * 0.3f);
        renderer.vertex(p3.x, p3.y, 0);

        renderer.color(color2.r, color2.g, color2.b, color2.a * 0.3f);
        renderer.vertex(p3.x, p3.y, 0);
        renderer.color(color1.r, color1.g, color1.b, color1.a * 0.3f);
        renderer.vertex(p4.x, p3.y - tinkness, 0);
        renderer.color(color1.r, color1.g, color1.b, color1.a * 0.3f);
        renderer.vertex(p1.x, p2.y - tinkness, 0);
    }
    Engine.getShapeRenderer().end();


    fbo.begin();
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    Engine.getSpriteBatch().setColor(color2);
    Engine.getSpriteBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    Engine.getSpriteBatch().begin();
    for (Particle p : particles) {
        Engine.getSpriteBatch().draw(particleTexture, p.Position.x, p.Position.y,
                0, 0, particleTexture.getRegionWidth(), particleTexture.getRegionHeight(),
                1, 1, p.Orientation);
    }
    Engine.getSpriteBatch().end();
    Engine.getSpriteBatch().setShader(null);
    fbo.end();

    Engine.getSpriteBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    Engine.getSpriteBatch().begin();
    Engine.getSpriteBatch().draw(fbo.getColorBufferTexture(), 0, 0, fbo.getColorBufferTexture().getWidth(), fbo.getColorBufferTexture().getHeight(), 0, 0, 1, 1);
    Engine.getSpriteBatch().end();
    Engine.getSpriteBatch().setColor(Color.WHITE);
    Engine.getSpriteBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
}