Reputation: 863
I am facing some rendering issues. Trying to build a 2d platform game, my plan is to create the actor with blender. I am new to both, blender and libgdx, and dont know where the error is.
In Blender, the actor looks fine. rendered by libgdx I see only odd forms, not at all looking like my actor.
----- EDIT ok, I narrowed down the issue. In blender I created a simple cube. This cube is rendered fine in my libgdx app, if I render only the cube and nothing else. The problem occurs, If I render my other (2d) elements before and I think I do something wrong there.
Maybe, because I have 2 cameras? A PerspectiveCamera for the cube, an OrthographicCamera for the rest..
The cube is rendered here:
@Override public void render () { //System.out.println("render"); if (loading && assets.update()) doneLoading(); camController.update();
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
modelBatch.render(instances, environment);
modelBatch.end();
}
My Main class has a render method as well. And from there the cube render is called:
@Override
public void render() {
this.handleInput();
//this.handleContacts();
this.moveCamera();
GL10 gl = Gdx.graphics.getGL10();
// Camera --------------------- /
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glViewport((int) glViewport.x, (int) glViewport.y,
(int) glViewport.width, (int) glViewport.height);
//tiledMapCam.zoom = 1f;
tiledMapCam.update();
tiledMapCam.apply(gl);
// background
tileRenderer.setView(tiledMapCam);
tileRenderer.render();
batch.setProjectionMatrix(tiledMapCam.combined);
batch.begin();
for (Ball b : balls)
b.render();
for (Rock r : rocks)
r.render();
player.render();
spieler3d.render();
batch.end();
// Box2d
physics.step();
updateObjects();
physics.debugRenderer.render(physics.world, tiledMapCam.combined);
}
----- END EDIT
I tried to adapt a sample from libgdx for rendering the actor. This is in class Spieler3d.
public class Spieler3d implements IObject {
AssetManager assets;
PerspectiveCamera camera;
ModelInstance instance;
ModelBatch modelBatch;
SpriteBatch spriteBatch;
@Override
public void create() {
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
camera.position.set(1,1,1);
camera.lookAt(0,0,0);
camera.near = 1;
camera.far = 100;
camera.update();
assets = new AssetManager();
assets.load("models/person_animated.g3dj", Model.class);
spriteBatch = new SpriteBatch();
modelBatch = new ModelBatch();
// assets.getLogger().setLevel(Logger.DEBUG);
}
private void doneLoading() {
instance = new ModelInstance(assets.get("models/person_animated.g3dj",
Model.class));
}
float counter;
@Override
public void render() {
if ((instance != null)
&& ((counter += Gdx.graphics.getDeltaTime()) >= 1f)) {
counter = 0f;
instance = null;
assets.unload("models/person_animated.g3dj");
assets.load("models/person_animated.g3dj", Model.class);
assets.finishLoading();
}
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
if (assets.update()) {
doneLoading();
}
if (instance != null) {
modelBatch.begin(camera);
modelBatch.render(instance);
modelBatch.end();
}
}
@Override
public void dispose() {
assets.dispose();
modelBatch.dispose();
spriteBatch.dispose();
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void setPosition(float x2, float y2) {
// TODO Auto-generated method stub
}
@Override
public float getWidth() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getHeight() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getX() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getY() {
// TODO Auto-generated method stub
return 0;
}
}
Upvotes: 0
Views: 285
Reputation: 66
It doesn't look like you're parsing the model when before creating the instance of it.
JsonModelLoader loader = new JsonModelLoader();
model = new Model(loader.parseModel(Gdx.files.internal("models/person_animated.g3dj", null));
instance = new ModelInstance(model);
Source: http://www.badlogicgames.com/wordpress/?p=2967
Upvotes: 0