0

プログラムで作成されたテクスチャを使用した一種の床が欲しいのですが。作業に必要な頂点とインデックスをすでに作成しました。

private VertexPositionNormalTexture[] verticiBase;
private short[] indici;

...

verticiBase = new VertexPositionNormalTexture[4];
verticiBase[0] = new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 0.0f), Vector3.Up, new Vector2(0, 0));
verticiBase[1] = new VertexPositionNormalTexture(new Vector3(dimensioneVera.X, 0.0f, 0.0f), Vector3.Up, new Vector2(1, 0));
verticiBase[2] = new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, dimensioneVera.Y), Vector3.Up, new Vector2(0, 1));
verticiBase[3] = new VertexPositionNormalTexture(new Vector3(dimensioneVera.X, 0.0f, dimensioneVera.Y), Vector3.Up, new Vector2(1, 1));

graphics.GraphicsDevice.VertexDeclaration = new 
    VertexDeclaration(graphics.GraphicsDevice,
    VertexPositionNormalTexture.VertexElements);

indici = new short[6];
indici[0] = 0;
indici[1] = 1;
indici[2] = 2;
indici[3] = 1;
indici[4] = 3;
indici[5] = 2;

次に、表示したいテクスチャとデータを作成しました。

private Texture2D texture;
private Color[] textureData;

...

texture = new Texture2D(Game.GraphicsDevice, (int)dimensioneVera.X, (int)dimensioneVera.Y);
textureData = new Color[(int)dimensioneVera.X * (int)dimensioneVera.Y];

for (int x = 0; x < textureData.Length; x++)
    textureData[x] = Color.Red;

texture.SetData(textureData);

そして、これは私が描くために使用したコードです:

private BasicEffect effetti;

...

effetti = new BasicEffect(graphics.GraphicsDevice, null);

...

public override void Draw(GameTime gameTime)
{
    effetti.World = Matrix.Identity;
    effetti.View = camera.view;
    effetti.Projection = camera.projection;

    effetti.TextureEnabled = true;
    effetti.Texture = texture;

    effetti.Begin();
    effetti.EnableDefaultLighting();

    effetti.CurrentTechnique.Passes[0].Begin();
    graphics.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
        verticiBase, 0, verticiBase.Length, indici, 0, indici.Length / 3);

    effetti.CurrentTechnique.Passes[0].End();

    effetti.End();

    base.Draw(gameTime);
}

床は表示されていますが、テクスチャはすべて黒です。どうしたの?

御時間ありがとうございます。

4

1 に答える 1

1

問題は、テクスチャを正しく作成していないことではないと思います。問題はあなたの照明です。電話をかけましEnableDefaultLighting()たが、ライトが提供されていないため、すべてが完全に暗くなります(黒)。設定effetti.AmbientLightColor = Color.Whiteしてみて、それが役立つかどうかを確認してください。

于 2011-09-02T21:38:02.733 に答える