user3161752
user3161752

Reputation: 45

LibGdx Rendering images on a surface in 3D

How can I render an image on a surface in 3D environment? I know how to render 3D shapes and 2D sprites but how would I put a certain picture on one side of a cube/box for instance? or for instance I want to create a 2D square and put a picture on both sides of it then render the whole thing in my 3D environment. Or a box with different images on each side. I dont know if I am making sense.

I am using libGdx on eclipse by the way.

Upvotes: 0

Views: 1362

Answers (1)

noone
noone

Reputation: 19776

I have some code like the following in my game. The wall is a simple box model that I generate in code. The texture is applied via a Material.

private static final ModelBuilder MODEL_BUILDER = new ModelBuilder();

public static Model createWall(float width, float height, float depth) {
    Texture texture = new Texture("wall.png");
    Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
    long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
    Model wall = MODEL_BUILDER.createBox(width, height, depth, material, attributes);

    return wall;
}

After that you can create a ModelInstance from that (new ModelInstance(wallModel)) and then render it via ModelBatch.

Upvotes: 0

Related Questions