java - LIBGDX 3D not working -
so starting off 3d part of libgdx. downloaded latest nightly build , when followed tutorial got nullpointerexception on line(which mark in code). on line has nullpointer code
modelbatch.render(instance); all values line there. instance has properties , pretty else in code to. ideas why getting nullpointerexception? in advance.
import com.badlogic.gdx.applicationlistener; import com.badlogic.gdx.gdx; import com.badlogic.gdx.graphics.color; import com.badlogic.gdx.graphics.gl10; import com.badlogic.gdx.graphics.perspectivecamera; import com.badlogic.gdx.graphics.vertexattributes.usage; import com.badlogic.gdx.graphics.g3d.model; import com.badlogic.gdx.graphics.g3d.modelbatch; import com.badlogic.gdx.graphics.g3d.modelinstance; import com.badlogic.gdx.graphics.g3d.materials.colorattribute; import com.badlogic.gdx.graphics.g3d.materials.material; import com.badlogic.gdx.graphics.g3d.utils.modelbuilder; public class threedtest implements applicationlistener { public perspectivecamera camera; public modelbatch modelbatch; public model model; public modelinstance instance; @override public void create() { camera = new perspectivecamera(67, gdx.graphics.getwidth(), gdx.graphics.getheight()); camera.position.set(10f, 10f, 10f); camera.lookat(0, 0, 0); camera.near = 0.1f; camera.far = 300f; camera.update(); modelbuilder modelbuilder = new modelbuilder(); model = modelbuilder.createbox(5f, 5f, 5f, new material(colorattribute.creatediffuse(color.green)), usage.position | usage.normal); instance = new modelinstance(model); } @override public void resize(int width, int height) { } @override public void render() { gdx.gl.glviewport(0, 0, gdx.graphics.getwidth(), gdx.graphics.getheight()); gdx.gl.glclear(gl10.gl_color_buffer_bit | gl10.gl_depth_buffer_bit); modelbatch.begin(camera);//begin rendering modelbatch.render(instance);<--null pointer on line modelbatch.end();//end rendering } @override public void pause() { } @override public void resume() { } @override public void dispose() { model.dispose(); } }
looking @ code never construct (and dispose) modelbatch instance. therefor modelbatch null, causing npe got.
add following line in create method:
modelbatch = new modelbatch(); and following line in dispose method:
modelbatch.dispose();
Comments
Post a Comment