OpenGLの基本的な知識はありますが、私はlibgdxから始めるところです。libgdx:PerspectiveCameraでSpriteBatchが表示されない
私の質問は、まったく同じコードで、OrthographicCameraからPerspectiveCameraに切り替えるだけで、私のSpriteBatchesが表示されなくなったということです。
ここで私が使用するコードです:
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();
}
と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();
}
、私のリサイズ(int型の幅であればは、 、int height)メソッドカメラを次のように設定しました。
public void resize(int width, int height) {
float aspectRatio = (float) width/(float) height;
camera = new OrthographicCamera(cameraViewHeight * aspectRatio, cameraViewHeight);
私はこの取得:
をしかし、私はカメラの種類変更した場合:
public void resize(int width, int height) {
float aspectRatio = (float) width/(float) height;
camera = new PerspectiveCamera(64, cameraViewHeight * aspectRatio, cameraViewHeight);
}
を、私はこれを取得:
私が求めている理由は、私はOpenGLでテキスト(フォント)を描く能力を持つlibgdxの機能が本当に好きだったからです。しかし、それらの例では、SpriteBatchを使用してFontインスタンスに渡り、常にOrtho Cameraを使用します。 SpriteBatchとFont描画機能がPerspectiveCameraで動作するかどうかを知りたい。
私は[デカール]だと思うPerspectiveCameraを使用している場合(http://code.google.com/p/libgdx-users/wiki/Decals)とDecalBatchクラスは、libgdx作成者が私たちが意図したものです。 – Sundae
コードには長すぎる行が含まれています(スクロールコードは水平ではありません)(答えも) –
ちょうど2台のカメラを使うことができます。抽象化。 –