1

まず第一に、私は XNA と、GPU がどのように機能し、XNA (または DirectX) API とどのように連携するかについては初めてです。

SpriteBatch を使用して描画するポリゴンがあります。ポリゴンを三角測量しVertexPositionTexture、頂点を保持する配列を作成しています。頂点を設定し (簡単にするために、テクスチャ オフセット ベクトルをゼロに設定し)、プリミティブを描画しようとしましたが、次のエラーが発生しました。

The current vertex declaration does not include all the elements required by the current vertex shader. Color0 is missing.

これが私のコードです。三角形分割からのベクトルを再確認しましたが、問題ありません。

        VertexPositionTexture[] vertices = new VertexPositionTexture[triangulationResult.Count * 3];
        int ctr = 0;
        foreach (var item in triangulationResult)
        {
            foreach (var point in item.Vertices)
            {
                vertices[ctr++] = new VertexPositionTexture(new Vector3(point.X, point.Y, 0), Vector2.Zero);
            }
        }

        sb.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, triangulationResult.Count);

ここで何が間違っているのでしょうか?

4

2 に答える 2

2

Your shader is expecting a Color in the vertex stream.... so you have to use VertexPositionColorTexture or change your shader.

It seems that you are not using any shader. If the active shader is the one used with spritebatch you won't be able to draw it right.

    VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[triangulationResult.Count * 3];
    int ctr = 0;
    foreach (var item in triangulationResult)
    {
        foreach (var point in item.Vertices)
        {
            vertices[ctr++] = new VertexPositionColorTexture(new Vector3(point.X, point.Y, 0), Color.White, Vector2.Zero);
        }
    }

    sb.GraphicsDevice.DrawUserPrimitives<VertexPositionColorTexture>(PrimitiveType.TriangleList, vertices, 0, triangulationResult.Count);
于 2011-10-28T23:49:13.503 に答える
1

BasicEffectポリゴンを描画する場合に使用します ( MSDN チュートリアル)。SpriteBatchスプライトの描画 (つまり、そのDrawメソッドの使用)にのみ使用する必要があります。

必要な頂点要素のタイプは、BasicEffect適用する設定によって異なります。

色コンポーネントのない頂点要素タイプ ( など) を使用するには、falseVertexPositionTextureに設定します。BasicEffect.VertexColorEnabled

あるいは、 などの色を提供する頂点要素タイプを使用しVertexPositionColorTextureます。

BasicEffectと同じ座標系を持つを作成する場合は、この回答またはこのブログ投稿SpriteBatchを参照してください。

于 2011-10-29T06:18:05.510 に答える