0

I am trying to add text to a scene using ModelBatch in LibGDX. To explain in more details, let's assume I have a class MyOBJ:

class MyOBJ {
    private Model model;
    private ModelInstance modelInstance;

    public MyOBJ() {
        // initialize model, texture and modelInstance.
        // for simplicity let's assume this is a sphere
        ModelBuilder modelBuilder = new ModelBuilder();
        model = modelBuilder.createSphere(...);
        instance = new ModelInstance(model);
    }

    public void render(ModelBatch modelBatch) {
        modelBatch.render(this.instance);
    }
}

Now, I want the sphere to have a text below (like a label). So that even if the camera rotates or moves, it will still be readable and below the sphere.

I know how to render text using a SpriteBatch, however, I can't seem to integrate the SpriteBatch (which is 2D) in a 3D model.

Petre Popescu
  • 1,950
  • 3
  • 24
  • 38
  • What you are asking for is an extremely complex topic that would require much more explanation than is customary to supply here on Stack Overflow. I recommend searching YouTube for a tutorial, in particular search for ThinMatrix, he has a Text rendering tutorial in lwjgl that would most likely be easily translated to LibGDX as the real meat of what you are trying to do is going to come down to heavy maths. – CraigR8806 Jan 27 '17 at 19:01
  • I see. I though LibGDX already offers some mechanism for combining 2D and 3D that I could not find in the documentation. I will try what you suggested. Thanks. – Petre Popescu Jan 27 '17 at 19:04
  • Not all that difficult really. You can pass a 3D transform matrix to SpriteBatch to change the plane that everything is drawn on. There is a question on this site where this was explained. – Tenfour04 Jan 27 '17 at 19:57
  • http://stackoverflow.com/questions/24375179/libgdx-decal-dynamic-text/24389207#24389207 – Tenfour04 Jan 27 '17 at 20:14

1 Answers1

2

I have managed to do this via decals. Render font into custom fbo, get fbo texture and add it to decal. Render everything with decal batch.

Veljko
  • 1,893
  • 6
  • 28
  • 58