Question

I haven't found any example which uses perspective camera in LibGDX(OpenGL ES 2.0). How to initiate it and use it in render method? Any help will be appreciated!

Was it helpful?

Solution

To some extent you can use a perspective camera as the ortho camera (to set position, look at, up vector). The one big difference is that the viewport size (what you see on screen) is determined by the distance to the object and the field of view angle. There is plenty of theory around the web, but to get started in libgdx you can follow this example

EDIT: Example provided uses GL 1.x I thought you just didn't know how to use a perspective camera. You mixed up two different problems.

  1. How to manipulate cameras (varies with camera type, regardless of GL version),
  2. How to apply cameras (varies with GL version, regardless of camera type).

To complete my answer, once you updated your camera (cam.update) insted of calling camera.apply(Gdx.gl10); you give the matrix to your shader - it will depend on your shader, but the simplest case would be something like this:

shader.setUniformMatrix("u_modelviewporj_mat", cam.combined);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top