Si bien tengo los conocimientos básicos de OpenGL recién estoy comenzando con libgdx.libgdx: SpriteBatch no se muestra con PerspectiveCamera
Mi pregunta es: ¿por qué tener exactamente el mismo código pero solo cambiar de OrthographicCamera a PerspectiveCamera tiene el efecto de no mostrar ninguno de mis SpriteBatches?
Aquí está el código que utilizo:
el método create():
public void create() {
textureMesh = new Texture(Gdx.files.internal("data/texMeshTest.png"));
textureSpriteBatch = new Texture(Gdx.files.internal("data/texSpriteBatchTest.png"));
squareMesh = new Mesh(true, 4, 4,
new VertexAttribute(Usage.Position, 3, "a_position")
,new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")
);
squareMesh.setVertices(new float[] {
squareXInitial, squareYInitial, squareZInitial, 0,1, //lower left
squareXInitial+squareSize, squareYInitial, squareZInitial, 1,1, //lower right
squareXInitial, squareYInitial+squareSize, squareZInitial, 0,0, //upper left
squareXInitial+squareSize, squareYInitial+squareSize, squareZInitial,1,0}); //upper right
squareMesh.setIndices(new short[] { 0, 1, 2, 3});
spriteBatch = new SpriteBatch();
}
y el método render():
public void render() {
GLCommon gl = Gdx.gl;
camera.update();
camera.apply(Gdx.gl10);
spriteBatch.setProjectionMatrix(camera.combined);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glEnable(GL10.GL_TEXTURE_2D);
textureMesh.bind();
squareMesh.render(GL10.GL_TRIANGLE_STRIP, 0, 4);
spriteBatch.begin();
spriteBatch.draw(textureSpriteBatch, -10, 0);
spriteBatch.end();
}
Ahora, si en mi cambio de tamaño (anchura int , int altura) método configuré la cámara como sigue:
public void resize(int width, int height) {
float aspectRatio = (float) width/(float) height;
camera = new OrthographicCamera(cameraViewHeight * aspectRatio, cameraViewHeight);
me sale esto:
Pero si cambio el tipo de cámara:
public void resize(int width, int height) {
float aspectRatio = (float) width/(float) height;
camera = new PerspectiveCamera(64, cameraViewHeight * aspectRatio, cameraViewHeight);
}
me sale esto:
La razón por la que estoy pidiendo es porque realmente me gustó la capacidad de libgdx de dibujar texto (fuente) en OpenGL. Pero en sus ejemplos usan un SpriteBatch que dirigen a la instancia de Font, y también siempre usan Ortho Camera. Me gustaría saber si SpriteBatch y la funcionalidad de dibujo de fuentes funcionan con PerspectiveCamera.
Cuando se utiliza el PerspectiveCamera creo que el [Etiqueta] (http://code.google.com/p/libgdx-users/wiki/Decals) y las clases DecalBatch son lo que los autores de libgdx quisieron que usáramos. – Sundae
El código contiene líneas demasiado largas (el código de desplazamiento horizontal no es genial) (también en la respuesta) –
por cierto, supongo que puede usar simplemente 2 cámaras: todo lo que hace es ocultar cálculos de matriz "de miedo" detrás de "simple" abstracciones –