Ok, ok, I solved this:
Short answer:
SpriteBatch uses OrthogonalPerpective internally. If you are using PerspectiveCamera, you need to pass the custom view matrix to SpriteBatch. You can do this in the resize method (...):
@Override public void resize(int width, int height) { float aspectRatio = (float) width / (float) height; camera = new PerspectiveCamera(64, cameraViewHeight * aspectRatio, cameraViewHeight); viewMatrix = new Matrix4(); viewMatrix.setToOrtho2D(0, 0,width, height); spriteBatch.setProjectionMatrix(viewMatrix); }
And then there is no need to do anything else with this matrix of project sprites (if you do not want to change the way the sprite is displayed on the screen):
public void render() { GLCommon gl = Gdx.gl; camera.update(); camera.apply(Gdx.gl10);
Long answer: since my final goal was to use SpriteBatch to draw text, while with the above modification of my code I can do this in the sense that both the sprite text and the mesh with texture are now visible, I noticed that if I donβt specify a color for the vertices of my grid, the indicated vertices will get the color that I use for the text. In other words, a textured mesh is declared like this:
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,
also having this code in my render (...) method will make the grid red tinted:
font.setColor(Color.RED); spriteBatch.draw(textureSpriteBatch, 0, 0); font.draw(spriteBatch, (int)fps+" fps", 0, 100);
Fix this to set colors on your mesh vertices from the start:
squareMesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, "a_position") ,new VertexAttribute(Usage.ColorPacked, 4, "a_color") ,new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords") ); squareMesh.setVertices(new float[] { squareXInitial, squareYInitial, squareZInitial, Color.toFloatBits(255, 255, 255, 255), 0,1,