DRiFTy
DRiFTy

Reputation: 11369

Map Texture around Sphere OpenGL ES Android

I'm trying to map a single texture around a sphere that I exported from Blender. The model looked great in Blender but when I use it in my Android application the texture appears to be mapped to almost every face, not the whole sphere. Any ideas? I am using libGDX on Android.

The setup code:

    model = G3dtLoader.loadStillModel(Gdx.files.internal("models/planet.g3dt"), true);

    for(StillSubMesh mesh: model.subMeshes) {
        mesh.mesh.scale(0.1f, 0.1f, 0.1f);
    }

    G3dExporter.export(model, Gdx.files.local("models/planet.g3d"));
    model = G3dLoader.loadStillModel(Gdx.files.local("models/planet.g3d"));

    texture = new Texture(Gdx.files.internal("textures/planet1_pot.png"), true);

    bounds = new BoundingBox();
    model.getBoundingBox(bounds);
    float len = bounds.getDimensions().len();

    cam = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(bounds.getCenter().cpy().add(len / 2, len / 2, len / 2));
    cam.lookAt(bounds.getCenter().x, bounds.getCenter().y, bounds.getCenter().z);
    cam.near = 0.1f;
    cam.far = 1000;

    renderer = new ImmediateModeRenderer10();

The rendering code:

    @Override
    public void renderScreen(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1.0f);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);

        cam.update();
        cam.apply(Gdx.gl10);

        if(texture != null) {
            Gdx.gl.glActiveTexture(GL10.GL_TEXTURE);
            Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);
            texture.bind();
        }

        model.render();

        if(texture != null) {
            Gdx.gl.glActiveTexture(GL10.GL_TEXTURE);
            Gdx.gl.glDisable(GL10.GL_TEXTURE_2D);
        }
    }

Edit: Here is a screenshot demonstrating my problem: enter image description here

Upvotes: 2

Views: 2276

Answers (1)

DRiFTy
DRiFTy

Reputation: 11369

I ended up figuring this problem out. I re-created my model in Blender following this link which says it's deprecated and lacks the screenshots but it helped me out. I ended up just exporting my model as a .obj and the texture now maps to the whole sphere.

Upvotes: 1

Related Questions