1

I can't figure out, how I to tell libgdx to draw my green spheres behind my transparent decal.

Here is an example picture of my problem:

enter image description here

The decal creation: first two params are width and height, last flag is wether transparent or not.

Decal.newDecal(count * (GUTTER + BUTTONWIDTH) + GUTTER, 2 * GUTTER + BUTTONHEIGHT, 
            new TextureRegion(new Texture(Gdx.files.internal("icons/uibg.png"))), true);

The sphere creation:

builder.createSphere(
            FINGERTIPRADIUS * 2, FINGERTIPRADIUS * 2, FINGERTIPRADIUS * 2,
            6, 6,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

And the render method:

this.models = new ModelBatch();
this.decals = new DecalBatch(new CameraGroupStrategy(camera));
...
// adding decals and models to render queue
...

public void update(float deltaTime){
    super.update(deltaTime);

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    models.begin(camera);
    for (Entity entity : queue) {
        ModelInstance model = Mappers.Object.get(entity).instance;
        models.render(model, environment);
    }

    decals.flush();

    models.end();
    queue.clear();
}

I appreciate every advice.

//EDIT

Added the Blendingattribute to the spheres and a .7 opacitiy. This works. But i guess the problem is somehow between the decal and model rendering, because the grid in the background is a decal and it can be seen through the black transparent decal but the spheres can't.

The new material code:

    Material mat = new Material();
    mat.set(ColorAttribute.createDiffuse(Color.GREEN));
    mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.7f));
    fingerTip = builder.createSphere(
            FINGERTIPRADIUS * 2, FINGERTIPRADIUS * 2, FINGERTIPRADIUS * 2,
            6, 6,
            mat,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

Here another picture: the two mid spheres are not rendered behind the transparent decal as they should.

enter image description here

Tenfour04
  • 83,111
  • 11
  • 94
  • 154
unreal
  • 11
  • 3
  • Please give us some code to see what you are doing. We just can guess here. For example add the render and model instance creation code. – bemeyer Aug 29 '15 at 16:44
  • You need to add Blending infos for example `materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));` – bemeyer Aug 30 '15 at 10:08

1 Answers1

1

Call models.end() before decals.flush(). Transparent stuff must be drawn after opaque stuff. Right now you are drawing the decal first, so it is writing its depth to the buffer before the spheres are drawn.

If your models are also transparent, this gets more complicated. You would need to sort your decals with your models somehow, and flush the rear models before you flush the decal, and finally flush the near models.

Tenfour04
  • 83,111
  • 11
  • 94
  • 154