I would like to render fixed text for debugging in my guiCam (second camera that is not affected by any rotations or transformations).
I think the text that is being rendered is either to big or to small to be seen in my perspective here, but I can't seem to find in the official libgdx documentation how the text is being draw and how I can manipulate the size.
create:
guiCam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
guiCam.position.set(1f, 1f, 20f);
guiCam.lookAt(0, 0, 0);
guiCam.near = 1f;
guiCam.far = 300f;
guiCam.update();
batch = new SpriteBatch();
batch.setProjectionMatrix(guiCam.combined);
font = new BitmapFont();
font.setColor(Color.RED);
render:
font.draw(batch, "debug line here", 200, 200);
Could someone perhaps explain to me how the libgdx default font is drawn, or if there might be a better solition to use here for displaying fixed text?
I allready tried to use OrthoGraphic camera instead of a prespective one, but since my main application is in 3D, the OrthoGraphic camera is does not work.
Found this for you on stackexchange.
Answer given by lookx2:
You can just use another SpriteBatch without setting projection matrix to draw the HUD,
camera.update();
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();
aButton.draw(spriteBatch, 1F);
playerShip.draw(spriteBatch, 1F);
spriteBatch.end();
hudBatch.begin();
//Draw using hudBatch
hudBatch.end();
If you want to render text on the screen then you'd want to do that by drawing to the HUD
I don't think it even works by mixing 2d and 3d batches. You should use Stage and StringBuilder with a single perspective camera.
For example, in create() function initialise the following
...
font = new BitmapFont();
//design the font
label = new Label("<text>", new Label.LabelStyle(font, Color.BLACK));
// set position
label.setPosition(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
stage = new Stage();
stage.addActor(label);
...
then in render() function use StringBuilder
...
StringBuilder builder = new StringBuilder();
//Change text at runtime
builder.append("<text>");
label.setText(builder);
stage.draw();
...
The example that helped me use it is from https://sudonull.com/post/91327-The-simplest-3D-game-on-libGDX-for-Android-in-200-lines-of-code
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.