libGdx を使用して 2D ゲームを作成しており、この特定の方法を使用して単純な 2D テクスチャを描画し、4 つの頂点を個別に指定しようとしています。
draw(Texture texture, float[] spriteVertices, int offset, int length)
説明: 指定された頂点を使用して四角形を描画します。4 つの頂点が必要で、それぞれが x、y、color、u、v の順に 5 つの要素で構成されています。
他の描画方法は正常に機能しますが、これを機能させることはできません。私がしようとしているのはこれです。
batch.draw(boxTexture, new float[] {-5, -5, 0, Color.toFloatBits(255, 0, 0, 255), 0, 0,
5, -5, 0, Color.toFloatBits(255, 255, 255, 255), 1, 0,
5, 5, 0, Color.toFloatBits(255, 255, 255, 255), 1, 1,
-5, 5, 0, Color.toFloatBits(255, 255, 255, 255), 0, 1}, 3, 3);
OpenGL がどのように機能するか、特にオフセットと長さがどうあるべきかについてはあまり詳しくありません。より知識のある人は、これを機能させる方法を知っていますか?
アップデート:
メッシュを使用して動作しますが、透明度がないことがわかり、迷惑です。最後に、SpriteBatch にカスタム メソッドを追加しました。頂点は時計回りに描画されます。
public void drawQuad (Texture texture, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float col) {
if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw.");
if (texture != lastTexture) {
switchTexture(texture);
} else if (idx == vertices.length) //
renderMesh();
final float u = 0;
final float v = 1;
final float u2 = 1;
final float v2 = 0;
vertices[idx++] = x1;
vertices[idx++] = y1;
vertices[idx++] = col;
vertices[idx++] = u;
vertices[idx++] = v;
vertices[idx++] = x2;
vertices[idx++] = y2;
vertices[idx++] = col;
vertices[idx++] = u;
vertices[idx++] = v2;
vertices[idx++] = x3;
vertices[idx++] = y3;
vertices[idx++] = col;
vertices[idx++] = u2;
vertices[idx++] = v2;
vertices[idx++] = x4;
vertices[idx++] = y4;
vertices[idx++] = col;
vertices[idx++] = u2;
vertices[idx++] = v;
}