I think this question must have been asked and answered somewhere, but I can’t find it!
I’m using libGDX (mainly because of his Android painless portability). I have setup a OrthographicCamera so my OpenGL coordinates are from -1f to 1f in the Y direction and from -ar to ar in the X direction (ar is a float with the aspect ratio of the screen resolution). Some code:
@Override
public void resize(int width, int height)
{
float ar = (float) width / (float) height;
camera = new OrthographicCamera(2f*ar, 2f);
}
In the game create() overridden method I setup a font using BitmapFont.
@Override
public void create()
{
sb = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("menuFont.fnt"), Gdx.files.internal("menuFont.png"), false);
}
Finally, in the render() method I update the camera, update the projection matrix in the SpriteBatch, and draw the font:
@Override
public void render()
{
camera.update();
camera.apply(Gdx.gl10);
sb.setProjectionMatrix(camera.combined); // HERE
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
sb.begin();
font.draw(sb, "Hola mundo", -100f, 10f);
sb.end();
}
This way, the font gets huge on the screen! (I could only see part of a letter).
What I want to do is to use OpenGL coordinates to position the text on the screen, but without any annoying scaling. I can disable the font scaling not passing the projection matrix to the SpirteBatch, i.e., commenting line with the “// HERE” comment. But can’t use OpenGL coordinates.
This must be a misconception I bear, but can’t figure it out!
Thanks in advance for any comment