Search in sources :

Example 26 with ColorAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project libgdx by libgdx.

the class MaterialTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
    // Create material attributes. Each material can contain x-number of attributes.
    textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture);
    colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE);
    blendingAttribute = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    ModelBuilder builder = new ModelBuilder();
    model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    model.manageDisposable(texture);
    modelInstance = new ModelInstance(model);
    modelInstance.transform.rotate(Vector3.X, 45);
    material = modelInstance.materials.get(0);
    builder.begin();
    MeshPartBuilder mpb = builder.part("back", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates, new Material(textureAttribute));
    mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1);
    backModel = builder.end();
    background = new ModelInstance(backModel);
    modelBatch = new ModelBatch();
    camera = new PerspectiveCamera(45, 4, 4);
    camera.position.set(0, 0, 3);
    camera.direction.set(0, 0, -1);
    camera.update();
    Gdx.input.setInputProcessor(this);
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) Texture(com.badlogic.gdx.graphics.Texture) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 27 with ColorAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute in project bdx by GoranM.

the class BDXShaderProvider method render.

public void render(Renderable renderable, Attributes combinedAttributes) {
    if (renderable.material.has(BlendingAttribute.Type)) {
        BlendingAttribute ba = (BlendingAttribute) renderable.material.get(BlendingAttribute.Type);
        Gdx.gl.glBlendFuncSeparate(ba.sourceFunction, ba.destFunction, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
    IntAttribute shadeless = (IntAttribute) renderable.material.get(Scene.BDXIntAttribute.Shadeless);
    if (shadeless == null)
        set(u_shadeless, 0);
    else
        set(u_shadeless, shadeless.value);
    ColorAttribute tint = (ColorAttribute) renderable.material.get(Scene.BDXColorAttribute.Tint);
    if (tint == null)
        set(u_tintColor, new Color());
    else
        set(u_tintColor, tint.color);
    ColorAttribute emit = (ColorAttribute) renderable.material.get(Scene.BDXColorAttribute.Emit);
    if (emit == null)
        set(u_emitColor, new Color());
    else
        set(u_emitColor, emit.color);
    if (shaderProvider.scene != null) {
        ColorAttribute fog = (ColorAttribute) renderable.environment.get(ColorAttribute.Fog);
        if (fog == null)
            set(u_fogRange, 0f, 0f);
        else
            set(u_fogRange, shaderProvider.scene.fogRange().x, shaderProvider.scene.fogRange().y);
        set(u_camRange, shaderProvider.scene.camera.near(), shaderProvider.scene.camera.far());
    }
    super.render(renderable, combinedAttributes);
}
Also used : BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) IntAttribute(com.badlogic.gdx.graphics.g3d.attributes.IntAttribute) Color(com.badlogic.gdx.graphics.Color) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)27 Environment (com.badlogic.gdx.graphics.g3d.Environment)17 Material (com.badlogic.gdx.graphics.g3d.Material)17 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)16 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)16 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)13 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)13 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)12 Texture (com.badlogic.gdx.graphics.Texture)8 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)5 Model (com.badlogic.gdx.graphics.g3d.Model)5 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4 BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)4 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)4 DirectionalShadowLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight)4 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 DepthShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)3